Class: Bisques::MultiQueueListener
- Inherits:
-
Object
- Object
- Bisques::MultiQueueListener
- Defined in:
- lib/bisques/queue_listener.rb
Overview
Listen for messages on several queues at the same time. The interface for objects of this class is identical to that of QueueListener.
Instance Method Summary collapse
-
#initialize(*queues) ⇒ MultiQueueListener
constructor
A new instance of MultiQueueListener.
-
#listen {|Message| ... } ⇒ Object
Listen for messages.
-
#listening? ⇒ Boolean
Returns true while the listener is active.
-
#stop ⇒ Object
Stop listening for messages.
Constructor Details
#initialize(*queues) ⇒ MultiQueueListener
Returns a new instance of MultiQueueListener.
69 70 71 72 |
# File 'lib/bisques/queue_listener.rb', line 69 def initialize(*queues) @queues = queues @listeners = [] end |
Instance Method Details
#listen {|Message| ... } ⇒ Object
Note:
Note that the block you give to this method is executed in a new thread.
Listen for messages. This is asynchronous and returns immediately.
80 81 82 83 84 85 86 87 88 89 |
# File 'lib/bisques/queue_listener.rb', line 80 def listen(&block) return if @listeners.any? @listeners = @queues.map do |queue| QueueListener.new(queue) end @listeners.each do |listener| listener.listen(&block) end end |
#listening? ⇒ Boolean
Returns true while the listener is active.
75 76 77 |
# File 'lib/bisques/queue_listener.rb', line 75 def listening? @listeners.any? end |
#stop ⇒ Object
Stop listening for messages.
92 93 94 95 |
# File 'lib/bisques/queue_listener.rb', line 92 def stop @listeners.each(&:stop) @listeners = [] end |