Class: Pantry::Communication::WaitList
- Inherits:
-
Object
- Object
- Pantry::Communication::WaitList
- Defined in:
- lib/pantry/communication/wait_list.rb
Overview
The WaitList manages futures for asynchronously waiting for responses from either the Client or the Server. Given an identity and a message, WaitList returns a Future that will be filled when the handler in question receives a message of the same Message type from that identity.
Defined Under Namespace
Classes: FutureResultWrapper
Instance Method Summary collapse
-
#initialize ⇒ WaitList
constructor
A new instance of WaitList.
- #received(message) ⇒ Object
-
#wait_for(message) ⇒ Object
Given a
messagebeing sent, create a Future for a response to this message. -
#waiting_for?(message) ⇒ Boolean
Is there a future waiting for this response message?.
Constructor Details
#initialize ⇒ WaitList
Returns a new instance of WaitList.
10 11 12 |
# File 'lib/pantry/communication/wait_list.rb', line 10 def initialize @futures = Hash.new {|hash, key| hash[key] = []} end |
Instance Method Details
#received(message) ⇒ Object
36 37 38 39 40 |
# File 'lib/pantry/communication/wait_list.rb', line 36 def received() if future = @futures[ .uuid ].shift future.signal(FutureResultWrapper.new()) end end |
#wait_for(message) ⇒ Object
Given a message being sent, create a Future for a response to this message. This keys off of the Message’s UUID, which must be kept in tact as it passes through the system.
17 18 19 20 21 |
# File 'lib/pantry/communication/wait_list.rb', line 17 def wait_for() future = Celluloid::Future.new @futures[ .uuid ] << future future end |
#waiting_for?(message) ⇒ Boolean
Is there a future waiting for this response message?
24 25 26 |
# File 'lib/pantry/communication/wait_list.rb', line 24 def waiting_for?() !@futures[ .uuid ].empty? end |