Class: NNQ::Routing::Pull
- Inherits:
-
Object
- Object
- NNQ::Routing::Pull
- Defined in:
- lib/nnq/routing/pull.rb
Overview
Instance Method Summary collapse
-
#close ⇒ Object
Wakes any waiters with nil so receive returns from a closed socket.
-
#close_read ⇒ Object
Wakes any waiters with nil, leaving the send side untouched (PULL has no send side — close_read is identical to close here, but kept separate for the ‘Socket#close_read` contract).
- #enqueue(body, _conn = nil) ⇒ Object
-
#initialize ⇒ Pull
constructor
A new instance of Pull.
-
#receive ⇒ String?
Message body, or nil if the queue was closed.
Constructor Details
#initialize ⇒ Pull
Returns a new instance of Pull.
15 16 17 |
# File 'lib/nnq/routing/pull.rb', line 15 def initialize @queue = Async::Queue.new end |
Instance Method Details
#close ⇒ Object
Wakes any waiters with nil so receive returns from a closed socket.
33 34 35 |
# File 'lib/nnq/routing/pull.rb', line 33 def close @queue.enqueue(nil) end |
#close_read ⇒ Object
Wakes any waiters with nil, leaving the send side untouched (PULL has no send side — close_read is identical to close here, but kept separate for the ‘Socket#close_read` contract).
41 42 43 |
# File 'lib/nnq/routing/pull.rb', line 41 def close_read @queue.enqueue(nil) end |
#enqueue(body, _conn = nil) ⇒ Object
20 21 22 |
# File 'lib/nnq/routing/pull.rb', line 20 def enqueue(body, _conn = nil) @queue.enqueue(body) end |
#receive ⇒ String?
Returns message body, or nil if the queue was closed.
26 27 28 |
# File 'lib/nnq/routing/pull.rb', line 26 def receive @queue.dequeue end |