Class: Future
- Inherits:
-
Object
- Object
- Future
- Defined in:
- lib/future.rb
Overview
A delayed-execution result, optimistically evaluated in a new thread.
Instance Method Summary (collapse)
-
- (Object) __force__
(also: #force)
The value of the future's evaluation.
-
- (Future) initialize { ... }
constructor
Creates a new future.
-
- (Boolean) respond_to?(method)
Does this future support the given method?.
Constructor Details
- (Future) initialize { ... }
Creates a new future.
19 20 21 22 |
# File 'lib/future.rb', line 19 def initialize(&block) @promise = ::Promise.new(&block) @thread = ::Thread.new { @promise.__force__ } end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
- (Object) method_missing(method, *args, &block) (private)
45 46 47 |
# File 'lib/future.rb', line 45 def method_missing(method, *args, &block) __force__.__send__(method, *args, &block) end |
Instance Method Details
- (Object) __force__ Also known as: force
The value of the future's evaluation. Blocks until result available.
28 29 30 31 |
# File 'lib/future.rb', line 28 def __force__ @thread.join if @thread @promise end |
- (Boolean) respond_to?(method)
Does this future support the given method?
39 40 41 |
# File 'lib/future.rb', line 39 def respond_to?(method) :force.equal?(method) || :__force__.equal?(method) || __force__.respond_to?(method) end |