Module: Kernel

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

Instance Method Summary collapse

Instance Method Details

#future { ... } ⇒ Future

Creates 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:

  • (Object)

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

Returns:



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

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

#promise { ... } ⇒ Promise

Creates a new promise.

Examples:

Lazily evaluate an arithmetic operation

x = promise { 3 + 3 }

Yields:

  • A block to be lazily evaluated.

Yield Returns:

  • (Object)

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

Returns:



87
88
89
# File 'lib/promise.rb', line 87

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