Class: Cql::CombinedFuture

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) ⇒ CombinedFuture

Returns a new instance of CombinedFuture.



413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
# File 'lib/cql/future.rb', line 413

def initialize(futures)
  super()
  values = Array.new(futures.size)
  remaining = futures.size
  futures.each_with_index do |f, i|
    f.on_value do |v|
      @lock.synchronize do
        values[i] = v
        remaining -= 1
      end
      if remaining == 0
        resolve(values)
      end
    end
    f.on_failure do |e|
      unless failed?
        fail(e)
      end
    end
  end
end