Class: Circus::Agents::Promise
- Inherits:
-
Object
- Object
- Circus::Agents::Promise
- Defined in:
- lib/circus/agents/client.rb
Overview
A promise provides a reference to an expected future result. Client calls return immediately upon message dispatch - in order to retrieve the final result, the promise can be inspected.
Instance Method Summary collapse
- #completed!(result) ⇒ Object
-
#initialize ⇒ Promise
constructor
A new instance of Promise.
- #result ⇒ Object
Constructor Details
#initialize ⇒ Promise
Returns a new instance of Promise.
52 53 54 55 56 57 |
# File 'lib/circus/agents/client.rb', line 52 def initialize @monitor = Monitor.new @cond = @monitor.new_cond @completed = false @result = nil end |
Instance Method Details
#completed!(result) ⇒ Object
59 60 61 62 63 64 65 |
# File 'lib/circus/agents/client.rb', line 59 def completed!(result) @monitor.synchronize do @completed = true @result = result @cond.signal end end |
#result ⇒ Object
67 68 69 70 71 72 73 74 |
# File 'lib/circus/agents/client.rb', line 67 def result @monitor.synchronize do return @result if @completed @cond.wait @result end end |