Class: Ferrum::Client::Subscriber
- Inherits:
-
Object
- Object
- Ferrum::Client::Subscriber
- Defined in:
- lib/ferrum/client/subscriber.rb
Constant Summary collapse
- INTERRUPTIONS =
%w[Fetch.requestPaused Fetch.authRequired].freeze
Instance Method Summary collapse
- #<<(message) ⇒ Object
- #clear(session_id:) ⇒ Object
- #close ⇒ Object
-
#initialize ⇒ Subscriber
constructor
A new instance of Subscriber.
- #on(event, &block) ⇒ Object
- #subscribed?(event) ⇒ Boolean
Constructor Details
#initialize ⇒ Subscriber
Returns a new instance of Subscriber.
8 9 10 11 12 13 14 |
# File 'lib/ferrum/client/subscriber.rb', line 8 def initialize @regular = Queue.new @priority = Queue.new @on = Concurrent::Hash.new { |h, k| h[k] = Concurrent::Array.new } start end |
Instance Method Details
#<<(message) ⇒ Object
16 17 18 19 20 21 22 |
# File 'lib/ferrum/client/subscriber.rb', line 16 def <<() if INTERRUPTIONS.include?(["method"]) @priority.push() else @regular.push() end end |
#clear(session_id:) ⇒ Object
38 39 40 |
# File 'lib/ferrum/client/subscriber.rb', line 38 def clear(session_id:) @on.delete_if { |k, _| k.match?(session_id) } end |
#close ⇒ Object
33 34 35 36 |
# File 'lib/ferrum/client/subscriber.rb', line 33 def close @regular_thread&.kill @priority_thread&.kill end |
#on(event, &block) ⇒ Object
24 25 26 27 |
# File 'lib/ferrum/client/subscriber.rb', line 24 def on(event, &block) @on[event] << block true end |
#subscribed?(event) ⇒ Boolean
29 30 31 |
# File 'lib/ferrum/client/subscriber.rb', line 29 def subscribed?(event) @on.key?(event) end |