Class: Faye::EventSource::Stream

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
EventMachine::Deferrable
Defined in:
lib/faye/eventsource.rb

Instance Method Summary collapse

Constructor Details

#initialize(event_source) ⇒ Stream

Returns a new instance of Stream.



98
99
100
101
102
103
104
# File 'lib/faye/eventsource.rb', line 98

def initialize(event_source)
  @event_source = event_source
  @connection   = event_source.env['em.connection']
  @stream_send  = event_source.env['stream.send']
  
  @connection.socket_stream = self if @connection.respond_to?(:socket_stream)
end

Instance Method Details

#each(&callback) ⇒ Object



106
107
108
# File 'lib/faye/eventsource.rb', line 106

def each(&callback)
  @stream_send ||= callback
end

#failObject



110
111
112
# File 'lib/faye/eventsource.rb', line 110

def fail
  @event_source.close
end

#receive(data) ⇒ Object



114
115
# File 'lib/faye/eventsource.rb', line 114

def receive(data)
end

#write(data) ⇒ Object



117
118
119
120
# File 'lib/faye/eventsource.rb', line 117

def write(data)
  return unless @stream_send
  @stream_send.call(data) rescue nil
end