class Concurrent::Promises::Future
e.g. when the tasks raises an exception.
Represents a value which will become available in future. May reject with a reason instead,
def any(event_or_future)
-
(Future)
-
def any(event_or_future) AnyResolvedFuturePromise.new_blocked_by2(self, event_or_future, @DefaultExecutor).future end
def apply(args, block)
def apply(args, block) internal_state.apply args, block end
def async_callback_on_fulfillment(state, executor, args, callback)
def async_callback_on_fulfillment(state, executor, args, callback) with_async(executor, state, args, callback) do |st, ar, cb| callback_on_fulfillment st, ar, cb end end
def async_callback_on_rejection(state, executor, args, callback)
def async_callback_on_rejection(state, executor, args, callback) with_async(executor, state, args, callback) do |st, ar, cb| callback_on_rejection st, ar, cb end end
def callback_on_fulfillment(state, args, callback)
def callback_on_fulfillment(state, args, callback) state.apply args, callback if state.fulfilled? end
def callback_on_rejection(state, args, callback)
def callback_on_rejection(state, args, callback) state.apply args, callback unless state.fulfilled? end
def callback_on_resolution(state, args, callback)
def callback_on_resolution(state, args, callback) callback.call(*state.result, *args) end
def delay
-
(Future)
-
def delay event = DelayPromise.new(@DefaultExecutor).event ZipFutureEventPromise.new_blocked_by2(self, event, @DefaultExecutor).future end
def exception(*args)
-
(Exception)
-
Raises:
-
(Concurrent::Error)
- when raising not rejected future
def exception(*args) raise Concurrent::Error, 'it is not rejected' unless rejected? raise ArgumentError unless args.size <= 1 reason = Array(internal_state.reason).flatten.compact if reason.size > 1 ex = Concurrent::MultipleErrors.new reason ex.set_backtrace(caller) ex else ex = if reason[0].respond_to? :exception reason[0].exception(*args) else RuntimeError.new(reason[0]).exception(*args) end ex.set_backtrace Array(ex.backtrace) + caller ex end end
def flat_event
-
(Event)
-
def flat_event FlatEventPromise.new_blocked_by1(self, @DefaultExecutor).event end
def flat_future(level = 1)
-
(Future)
-
Parameters:
-
level
(Integer
) -- how many levels of futures should flatten
def flat_future(level = 1) FlatFuturePromise.new_blocked_by1(self, level, @DefaultExecutor).future end
def fulfilled?
-
(Boolean)
-
def fulfilled? state = internal_state state.resolved? && state.fulfilled? end
def on_fulfillment(*args, &callback)
-
(self)
-
def on_fulfillment(*args, &callback) on_fulfillment_using @DefaultExecutor, *args, &callback end
def on_fulfillment!(*args, &callback)
- Yield: - to the callback.
Returns:
-
(self)
-
def on_fulfillment!(*args, &callback) add_callback :callback_on_fulfillment, args, callback end
def on_fulfillment_using(executor, *args, &callback)
- Yield: - to the callback.
Returns:
-
(self)
-
def on_fulfillment_using(executor, *args, &callback) add_callback :async_callback_on_fulfillment, executor, args, callback end
def on_rejection(*args, &callback)
-
(self)
-
def on_rejection(*args, &callback) on_rejection_using @DefaultExecutor, *args, &callback end
def on_rejection!(*args, &callback)
- Yield: - to the callback.
Returns:
-
(self)
-
def on_rejection!(*args, &callback) add_callback :callback_on_rejection, args, callback end
def on_rejection_using(executor, *args, &callback)
- Yield: - to the callback.
Returns:
-
(self)
-
def on_rejection_using(executor, *args, &callback) add_callback :async_callback_on_rejection, executor, args, callback end
def reason(timeout = nil, timeout_value = nil)
-
(Object, timeout_value)
- the reason, or timeout_value on timeout, or nil on fulfillment.
def reason(timeout = nil, timeout_value = nil) if wait_until_resolved timeout internal_state.reason else timeout_value end end
def rejected?
-
(Boolean)
-
def rejected? state = internal_state state.resolved? && !state.fulfilled? end
def rejected_resolution(raise_on_reassign, state)
def rejected_resolution(raise_on_reassign, state) if raise_on_reassign if internal_state == RESERVED raise Concurrent::MultipleAssignmentError.new( "Future can be resolved only once. It is already reserved.") else raise Concurrent::MultipleAssignmentError.new( "Future can be resolved only once. It's #{result}, trying to set #{state.result}.", current_result: result, new_result: state.result) end end return false end
def rescue(*args, &task)
-
(Future)
-
def rescue(*args, &task) rescue_on @DefaultExecutor, *args, &task end
def rescue_on(executor, *args, &task)
- Yield: - to the task.
Returns:
-
(Future)
-
def rescue_on(executor, *args, &task) RescuePromise.new_blocked_by1(self, @DefaultExecutor, executor, args, &task).future end
def result(timeout = nil)
-
(Array(Boolean, Object, Object), nil)
- triplet of fulfilled?, value, reason, or nil
def result(timeout = nil) internal_state.result if wait_until_resolved timeout end
def run(run_test = method(:run_test))
-
run_test
(#call(value)
) --
Returns:
-
(Future)
-
def run(run_test = method(:run_test)) RunFuturePromise.new_blocked_by1(self, @DefaultExecutor, run_test).future end
def run_test(v)
def run_test(v) v if v.is_a?(Future) end
def schedule(intended_time)
-
(Future)
-
def schedule(intended_time) chain do event = ScheduledPromise.new(@DefaultExecutor, intended_time).event ZipFutureEventPromise.new_blocked_by2(self, event, @DefaultExecutor).future end.flat end
def then(*args, &task)
-
(Future)
-
def then(*args, &task) then_on @DefaultExecutor, *args, &task end
def then_on(executor, *args, &task)
- Yield: - to the task.
Returns:
-
(Future)
-
def then_on(executor, *args, &task) ThenPromise.new_blocked_by1(self, @DefaultExecutor, executor, args, &task).future end
def to_event
-
(Event)
-
def to_event event = Promises.resolvable_event ensure chain_resolvable(event) end
def to_future
-
(Future)
-
def to_future self end
def to_s
-
(String)
- Short string representation.
def to_s if resolved? format '%s with %s>', super[0..-2], (fulfilled? ? value : reason).inspect else super end end
def value(timeout = nil, timeout_value = nil)
-
(Object, nil, timeout_value)
- the value of the Future when fulfilled,
Parameters:
-
timeout_value
(Object
) -- a value returned by the method when it times out
def value(timeout = nil, timeout_value = nil) if wait_until_resolved timeout internal_state.value else timeout_value end end
def value!(timeout = nil, timeout_value = nil)
-
(Exception)
- {#reason} on rejection
Returns:
-
(Object, nil, timeout_value)
- the value of the Future when fulfilled,
def value!(timeout = nil, timeout_value = nil) if wait_until_resolved! timeout internal_state.value else timeout_value end end
def wait!(timeout = nil)
-
(Exception)
- {#reason} on rejection
def wait!(timeout = nil) result = wait_until_resolved!(timeout) timeout ? result : self end
def wait_until_resolved!(timeout = nil)
def wait_until_resolved!(timeout = nil) result = wait_until_resolved(timeout) raise self if rejected? result end
def with_default_executor(executor)
-
(Future)
-
def with_default_executor(executor) FutureWrapperPromise.new_blocked_by1(self, executor).future end
def zip(other)
-
(Future)
-
def zip(other) if other.is_a?(Future) ZipFuturesPromise.new_blocked_by2(self, other, @DefaultExecutor).future else ZipFutureEventPromise.new_blocked_by2(self, other, @DefaultExecutor).future end end