Class: Ticketing::Waiter
- Inherits:
-
Object
- Object
- Ticketing::Waiter
- Defined in:
- lib/ticketing/connection.rb
Overview
A one-shot channel a caller blocks on until its reply (or a failure) arrives from the reader thread.
Instance Method Summary collapse
- #await ⇒ Object
- #complete(reply) ⇒ Object
- #fail(error) ⇒ Object
-
#initialize ⇒ Waiter
constructor
A new instance of Waiter.
Constructor Details
#initialize ⇒ Waiter
Returns a new instance of Waiter.
25 26 27 |
# File 'lib/ticketing/connection.rb', line 25 def initialize @queue = Queue.new end |
Instance Method Details
#await ⇒ Object
37 38 39 40 41 42 |
# File 'lib/ticketing/connection.rb', line 37 def await kind, value = @queue.pop raise value if kind == :err value end |
#complete(reply) ⇒ Object
29 30 31 |
# File 'lib/ticketing/connection.rb', line 29 def complete(reply) @queue.push([:ok, reply]) end |
#fail(error) ⇒ Object
33 34 35 |
# File 'lib/ticketing/connection.rb', line 33 def fail(error) @queue.push([:err, error]) end |