Class: Ticketing::Waiter

Inherits:
Object
  • Object
show all
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

Constructor Details

#initializeWaiter

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

#awaitObject



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