Module: Kernel

Defined in:
lib/future.rb,
lib/promise.rb

Instance Method Summary collapse

Instance Method Details

#future { ... } ⇒ Future

Create a new future

Examples:

Evaluate an operation in another thread

x = future { 3 + 3 }

Yields:

  • A block to be optimistically evaluated in another thread

Yield Returns:

  • (Any)

    The return value of the block will be the evaluated value of the future.

Returns:



63
64
65
# File 'lib/future.rb', line 63

def future(&block)
  Future.new(block)
end

#promise { ... } ⇒ Promise

Create a new promise

Examples:

Lazily evaluate an arithmetic operation

x = promise { 3 + 3 }

Yields:

  • A block to be lazily evaluated

Yield Returns:

  • (Any)

    The return value of the block will be the lazily evaluated value of the promise.

Returns:



81
82
83
# File 'lib/promise.rb', line 81

def promise(&block)
  Promise.new(block)
end