Module: Ione::Future::Blockers
- Included in:
- Ione::Future
- Defined in:
- lib/ione/future.rb
Overview
Instance Method Summary collapse
-
#await(f) ⇒ Object
Awaits the completion of a future and either returns the value or raises an error.
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.
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 |