Class: Runivedo::Future
- Inherits:
-
Object
- Object
- Runivedo::Future
- Defined in:
- lib/runivedo/future.rb
Instance Method Summary collapse
- #complete(value) ⇒ Object
- #fail(exception) ⇒ Object
- #get ⇒ Object
-
#initialize ⇒ Future
constructor
A new instance of Future.
- #is_complete? ⇒ Boolean
Constructor Details
#initialize ⇒ Future
Returns a new instance of Future.
5 6 7 8 9 10 |
# File 'lib/runivedo/future.rb', line 5 def initialize @mutex = Mutex.new @cond = ConditionVariable.new @success = nil @value = nil end |
Instance Method Details
#complete(value) ⇒ Object
31 32 33 34 35 36 37 |
# File 'lib/runivedo/future.rb', line 31 def complete(value) @mutex.synchronize do @success = true @value = value @cond.broadcast end end |
#fail(exception) ⇒ Object
23 24 25 26 27 28 29 |
# File 'lib/runivedo/future.rb', line 23 def fail(exception) @mutex.synchronize do @success = false @value = exception @cond.broadcast end end |
#get ⇒ Object
12 13 14 15 16 17 18 19 20 21 |
# File 'lib/runivedo/future.rb', line 12 def get @mutex.synchronize do @cond.wait(@mutex) while @success.nil? end if @success @value else raise @value end end |
#is_complete? ⇒ Boolean
39 40 41 |
# File 'lib/runivedo/future.rb', line 39 def is_complete? !@success.nil? end |