Class: Cql::FirstFuture

Inherits:
CompletableFuture show all
Defined in:
lib/cql/future.rb

Instance Method Summary collapse

Methods inherited from CompletableFuture

#fail, #resolve

Methods inherited from Future

#completed?, #failed?, #resolved?, #value

Methods included from FutureFactories

#all, #failed, #first, #resolved

Methods included from FutureCallbacks

#on_complete, #on_failure, #on_value

Methods included from FutureCombinators

#fallback, #flat_map, #map, #recover

Constructor Details

#initialize(futures) ⇒ FirstFuture

Returns a new instance of FirstFuture.



438
439
440
441
442
443
444
445
446
447
448
# File 'lib/cql/future.rb', line 438

def initialize(futures)
  super()
  futures.each do |f|
    f.on_value do |value|
      resolve(value) unless completed?
    end
    f.on_failure do |e|
      fail(e) if futures.all?(&:failed?)
    end
  end
end