Module: Ione::Future::Blockers

Included in:
Ione::Future
Defined in:
lib/ione/future.rb

Overview

Since:

  • v1.3.0

Instance Method Summary collapse

Instance Method Details

#await(f) ⇒ Object

Note:

This is a blocking operation and should be used with caution. You should never call this method in a block given to any of the other methods on Ione::Future. Prefer using combinator methods like Combinators#map and Combinators#flat_map to compose operations asynchronously, or use Callbacks#on_value, Callbacks#on_failure or Ione::Future#on_complete to listen for values and/or failures.

Awaits the completion of a future and either returns the value or raises an error.

Returns:

  • (Object)

    the value of this future

Raises:

  • (Error)

    the error that failed this future

Since:

  • v1.3.0



607
608
609
610
611
612
613
614
615
# File 'lib/ione/future.rb', line 607

def await(f)
  semaphore = Queue.new
  f.on_complete do |value, error|
    semaphore << [value, error]
  end
  value, error = semaphore.pop
  raise error if error
  value
end