Class: Faye::Connection
- Inherits:
-
Object
- Object
- Faye::Connection
- Extended by:
- Forwardable
- Includes:
- EventMachine::Deferrable, Observable
- Defined in:
- lib/faye/connection.rb
Constant Summary collapse
- MAX_DELAY =
0.1
- INTERVAL =
1.0
- TIMEOUT =
60.0
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Returns the value of attribute id.
Instance Method Summary collapse
- #connect(&block) ⇒ Object
- #disconnect! ⇒ Object
- #flush! ⇒ Object
-
#initialize(id, options = {}) ⇒ Connection
constructor
A new instance of Connection.
- #subscribe(channel) ⇒ Object
- #timeout ⇒ Object
- #unsubscribe(channel) ⇒ Object
- #update(event) ⇒ Object
Constructor Details
#initialize(id, options = {}) ⇒ Connection
Returns a new instance of Connection.
15 16 17 18 19 20 |
# File 'lib/faye/connection.rb', line 15 def initialize(id, = {}) @id = id @options = @channels = Set.new @inbox = Set.new end |
Instance Attribute Details
#id ⇒ Object (readonly)
Returns the value of attribute id.
13 14 15 |
# File 'lib/faye/connection.rb', line 13 def id @id end |
Instance Method Details
#connect(&block) ⇒ Object
42 43 44 45 46 47 48 49 50 51 |
# File 'lib/faye/connection.rb', line 42 def connect(&block) callback(&block) return if @connected @mark_for_deletion = false @connected = true begin_delivery_timeout! unless @inbox.empty? begin_connection_timeout! end |
#disconnect! ⇒ Object
64 65 66 67 |
# File 'lib/faye/connection.rb', line 64 def disconnect! unsubscribe(:all) flush! end |
#flush! ⇒ Object
53 54 55 56 57 58 59 60 61 62 |
# File 'lib/faye/connection.rb', line 53 def flush! return unless @connected release_connection! events = @inbox.entries @inbox = Set.new set_deferred_status(:succeeded, events) set_deferred_status(:deferred) end |
#subscribe(channel) ⇒ Object
26 27 28 |
# File 'lib/faye/connection.rb', line 26 def subscribe(channel) channel.add_observer(self) if @channels.add?(channel) end |
#timeout ⇒ Object
22 23 24 |
# File 'lib/faye/connection.rb', line 22 def timeout @options[:timeout] || TIMEOUT end |
#unsubscribe(channel) ⇒ Object
30 31 32 33 34 35 |
# File 'lib/faye/connection.rb', line 30 def unsubscribe(channel) return @channels.each(&method(:unsubscribe)) if channel == :all return unless @channels.member?(channel) @channels.delete(channel) channel.delete_observer(self) end |
#update(event) ⇒ Object
37 38 39 40 |
# File 'lib/faye/connection.rb', line 37 def update(event) @inbox.add(event) begin_delivery_timeout! if @connected end |