Class: EStream::Evented

Inherits:
Generic show all
Defined in:
lib/e-core/instance/stream.rb

Instance Method Summary collapse

Methods inherited from Generic

#callback, #close, #closed?, defer, #each, #initialize, schedule

Constructor Details

This class inherits a constructor from EStream::Generic

Instance Method Details

#data(data) ⇒ Object Also known as: <<

sending data

Examples:

event_stream :keep_open do |out|
  out.data 'chunk one'
  out.data 'chunk two'
  out.data 'etc.'
end


142
143
144
145
146
# File 'lib/e-core/instance/stream.rb', line 142

def data data
  # - any single message should not contain \n except at the end.
  # - EventSource expects \n\n at the end of each single message.
  write "data: %s\n\n" % data.gsub(/\n|\r/, '')
end

#write(data) ⇒ Object



149
150
151
# File 'lib/e-core/instance/stream.rb', line 149

def write data
  @scheduler.schedule { @front.call(data.to_s) }
end