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
-
#future ⇒ Concurrent::Future
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) @future = Concurrent::Future.execute(&block) end |
Instance Attribute Details
#future ⇒ Concurrent::Future (readonly)
Returns underlying thread running task.
8 9 10 |
# File 'lib/zoidberg/future.rb', line 8 def future @future end |
Instance Method Details
#available? ⇒ TrueClass, FalseClass
Check if value is available
29 30 31 |
# File 'lib/zoidberg/future.rb', line 29 def available? future.fulfilled? end |
#value ⇒ Object
Returns result value.
19 20 21 22 23 24 |
# File 'lib/zoidberg/future.rb', line 19 def value unless(@value) @value = @future.value end @value end |