class Future
A delayed-execution result, optimistically evaluated in a new thread.
@example
x = future { sleep 5; 1 + 2 } # do stuff... y = x * 2 # => 6. blocks unless 5 seconds has passed.
Public Class Methods
new(&block)
click to toggle source
Creates a new future.
@yield [] The block to evaluate optimistically. @see Kernel#future
# File lib/future.rb, line 19 def initialize(&block) @promise = ::Promise.new(&block) @thread = ::Thread.new { @promise.__force__ } end
Public Instance Methods
__force__()
click to toggle source
The value of the future’s evaluation. Blocks until result available.
@return [Object]
# File lib/future.rb, line 28 def __force__ @thread.join if @thread @promise end
Also aliased as: force
respond_to?(method, include_all=false)
click to toggle source
Does this future support the given method?
@param [Symbol] @return [Boolean]
# File lib/future.rb, line 39 def respond_to?(method, include_all=false) :force.equal?(method) || :__force__.equal?(method) || __force__.respond_to?(method, include_all) end
Private Instance Methods
method_missing(method, *args, &block)
click to toggle source
# File lib/future.rb, line 45 def method_missing(method, *args, &block) __force__.__send__(method, *args, &block) end