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
(also: #force)
The value of the future’s evaluation.
-
#initialize(block) { ... } ⇒ Future
constructor
Create a new future.
- #method_missing(method, *args, &block) ⇒ Object
-
#respond_to?(method) ⇒ true, false
Does this promise support the given method?.
Constructor Details
#initialize(block) { ... } ⇒ Future
Create a new future
19 20 21 22 23 24 |
# File 'lib/future.rb', line 19 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
46 47 48 |
# File 'lib/future.rb', line 46 def method_missing(method, *args, &block) @promise.send(method, *args, &block) end |
Instance Method Details
#__force__ ⇒ Any Also known as: force
The value of the future’s evaluation. Blocks until result available.
30 31 32 33 |
# File 'lib/future.rb', line 30 def __force__ @thread.join @promise end |
#respond_to?(method) ⇒ true, false
Does this promise support the given method?
41 42 43 |
# File 'lib/future.rb', line 41 def respond_to?(method) (method == :force) || (method == :__force__) || (__force__.respond_to?(method)) end |