Class: ThreadExecutor::Promise
- Inherits:
-
Object
- Object
- ThreadExecutor::Promise
- Defined in:
- lib/thread_executor/promise.rb
Overview
A Promise is a container for a value that a Processor will compute.
It contains locking objects to ensure that the value is communicated safely from the Processor ‘s Thread to user’s Thread.
A user typically never touches this object directly but examines the Future.
Instance Attribute Summary collapse
-
#exception ⇒ Object
Returns the value of attribute exception.
-
#future ⇒ Object
readonly
Returns the value of attribute future.
-
#value ⇒ Object
Wait until this Promise is fulfilled and return the value If an exception was raised, it is reraised here.
Instance Method Summary collapse
-
#initialize ⇒ Promise
constructor
A new instance of Promise.
- #ready? ⇒ Boolean
Constructor Details
#initialize ⇒ Promise
Returns a new instance of Promise.
43 44 45 46 47 48 49 50 51 |
# File 'lib/thread_executor/promise.rb', line 43 def initialize() @value = nil @exception = nil @ready = false @lock = Mutex.new @cond = ConditionVariable.new @no_result = true @future = Future.new(self) end |
Instance Attribute Details
#exception ⇒ Object
Returns the value of attribute exception.
41 42 43 |
# File 'lib/thread_executor/promise.rb', line 41 def exception @exception end |
#future ⇒ Object (readonly)
Returns the value of attribute future.
41 42 43 |
# File 'lib/thread_executor/promise.rb', line 41 def future @future end |
#value ⇒ Object
Wait until this Promise is fulfilled and return the value If an exception was raised, it is reraised here.
55 56 57 |
# File 'lib/thread_executor/promise.rb', line 55 def value @value end |
Instance Method Details
#ready? ⇒ Boolean
68 69 70 |
# File 'lib/thread_executor/promise.rb', line 68 def ready? @ready end |