Class: Faye::EventSource::Stream
- Inherits:
-
Object
- Object
- Faye::EventSource::Stream
- Extended by:
- Forwardable
- Includes:
- EventMachine::Deferrable
- Defined in:
- lib/faye/eventsource.rb
Instance Method Summary collapse
- #each(&callback) ⇒ Object
- #fail ⇒ Object
-
#initialize(event_source) ⇒ Stream
constructor
A new instance of Stream.
- #receive(data) ⇒ Object
- #write(data) ⇒ Object
Constructor Details
#initialize(event_source) ⇒ Stream
Returns a new instance of Stream.
99 100 101 102 103 104 105 |
# File 'lib/faye/eventsource.rb', line 99 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
107 108 109 |
# File 'lib/faye/eventsource.rb', line 107 def each(&callback) @stream_send ||= callback end |
#fail ⇒ Object
111 112 113 |
# File 'lib/faye/eventsource.rb', line 111 def fail @event_source.close end |
#receive(data) ⇒ Object
115 116 |
# File 'lib/faye/eventsource.rb', line 115 def receive(data) end |
#write(data) ⇒ Object
118 119 120 121 |
# File 'lib/faye/eventsource.rb', line 118 def write(data) return unless @stream_send @stream_send.call(data) rescue nil end |