class Concurrent::Promises::FlatFuturePromise
def initialize(delayed, blockers_count, levels, default_executor)
def initialize(delayed, blockers_count, levels, default_executor) raise ArgumentError, 'levels has to be higher than 0' if levels < 1 # flat promise may result to a future having delayed futures, therefore we have to have empty stack # to be able to add new delayed futures super delayed || LockFreeStack.new, 1 + levels, Future.new(self, default_executor) end
def process_on_blocker_resolution(future, index)
def process_on_blocker_resolution(future, index) countdown = super(future, index) if countdown.nonzero? internal_state = future.internal_state unless internal_state.fulfilled? resolve_with internal_state return countdown end value = internal_state.value case value when AbstractEventFuture add_delayed_of value value.add_callback_notify_blocked self, nil countdown else evaluate_to(lambda { raise TypeError, "returned value #{value.inspect} is not a Future" }) end end countdown end