Class: Zoidberg::Future
- Inherits:
-
Object
- Object
- Zoidberg::Future
- Defined in:
- lib/zoidberg/future.rb
Overview
Perform action and fetch result in the future
Instance Attribute Summary collapse
-
#thread ⇒ Thread
readonly
Underlying thread running task.
Instance Method Summary collapse
-
#available? ⇒ TrueClass, FalseClass
Check if value is available.
-
#initialize { ... } ⇒ self
constructor
Create a new instance.
-
#value ⇒ Object
Result value.
Constructor Details
#initialize { ... } ⇒ self
Create a new instance
14 15 16 |
# File 'lib/zoidberg/future.rb', line 14 def initialize(&block) @thread = Thread.new(&block) end |
Instance Attribute Details
#thread ⇒ Thread (readonly)
Returns underlying thread running task.
8 9 10 |
# File 'lib/zoidberg/future.rb', line 8 def thread @thread end |
Instance Method Details
#available? ⇒ TrueClass, FalseClass
Check if value is available
29 30 31 |
# File 'lib/zoidberg/future.rb', line 29 def available? !thread.alive? end |
#value ⇒ Object
Returns result value.
19 20 21 22 23 24 |
# File 'lib/zoidberg/future.rb', line 19 def value unless(@value) @value = @thread.value end @value end |