Class: Future
- Inherits:
-
Object
- Object
- Future
- Defined in:
- lib/future.rb
Overview
A delayed-execution result, optimistcally evaluated in a new Thread.
Instance Method Summary collapse
-
#force ⇒ Any
The value of the future’s evaluation.
- #initialize(block) ⇒ Future constructor
- #method_missing(method, *args, &block) ⇒ Object
Constructor Details
#initialize(block) ⇒ Future
17 18 19 20 21 22 |
# File 'lib/future.rb', line 17 def initialize(block) @promise = promise &block @thread = ::Thread.new do @promise.force end end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
33 34 35 |
# File 'lib/future.rb', line 33 def method_missing(method, *args, &block) @promise.send(method, *args, &block) end |
Instance Method Details
#force ⇒ Any
The value of the future’s evaluation. Blocks until result available.
27 28 29 30 |
# File 'lib/future.rb', line 27 def force @thread.join @promise end |