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.



93
94
95
96
97
98
99
# File 'lib/faye/eventsource.rb', line 93

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



101
102
103
# File 'lib/faye/eventsource.rb', line 101

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

#failObject



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

def fail
  @event_source.close
end

#receive(data) ⇒ Object



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

def receive(data)
end

#write(data) ⇒ Object



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

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