Class: Pubsubstub::Subscription
- Inherits:
-
Object
- Object
- Pubsubstub::Subscription
- Includes:
- Logging
- Defined in:
- lib/pubsubstub/subscription.rb
Instance Attribute Summary collapse
-
#channels ⇒ Object
readonly
Returns the value of attribute channels.
-
#connection ⇒ Object
readonly
Returns the value of attribute connection.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#queue ⇒ Object
readonly
Returns the value of attribute queue.
Instance Method Summary collapse
-
#initialize(channels, connection) ⇒ Subscription
constructor
A new instance of Subscription.
- #push(event) ⇒ Object
- #stream(last_event_id) ⇒ Object
Methods included from Logging
Constructor Details
#initialize(channels, connection) ⇒ Subscription
Returns a new instance of Subscription.
7 8 9 10 11 12 |
# File 'lib/pubsubstub/subscription.rb', line 7 def initialize(channels, connection) @id = Random.rand(2 ** 64) @connection = connection @channels = channels @queue = Queue.new end |
Instance Attribute Details
#channels ⇒ Object (readonly)
Returns the value of attribute channels.
5 6 7 |
# File 'lib/pubsubstub/subscription.rb', line 5 def channels @channels end |
#connection ⇒ Object (readonly)
Returns the value of attribute connection.
5 6 7 |
# File 'lib/pubsubstub/subscription.rb', line 5 def connection @connection end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
5 6 7 |
# File 'lib/pubsubstub/subscription.rb', line 5 def id @id end |
#queue ⇒ Object (readonly)
Returns the value of attribute queue.
5 6 7 |
# File 'lib/pubsubstub/subscription.rb', line 5 def queue @queue end |
Instance Method Details
#push(event) ⇒ Object
27 28 29 |
# File 'lib/pubsubstub/subscription.rb', line 27 def push(event) queue.push(event) end |
#stream(last_event_id) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/pubsubstub/subscription.rb', line 14 def stream(last_event_id) info { "Connecting client ##{id} (#{channels.map(&:name).join(', ')})" } subscribe fetch_scrollback(last_event_id) while event = queue.pop debug { "Sending event ##{event.id} to client ##{id}"} connection << event. end ensure info { "Disconnecting client ##{id}" } unsubscribe end |