class Concurrent::Promises::ResolvableFuture
A Future
which can be resolved by user.
Public Instance Methods
Evaluates the block and sets its result as future’s value fulfilling, if the block raises an exception the future rejects with it.
@yield [*args] to the block. @yieldreturn [Object] value @return [self]
# File lib/concurrent-ruby/concurrent/promises.rb, line 1385 def evaluate_to(*args, &block) promise.evaluate_to(*args, block) end
Evaluates the block and sets its result as future’s value fulfilling, if the block raises an exception the future rejects with it.
@yield [*args] to the block. @yieldreturn [Object] value @return [self] @raise [Exception] also raise reason on rejection.
# File lib/concurrent-ruby/concurrent/promises.rb, line 1396 def evaluate_to!(*args, &block) promise.evaluate_to(*args, block).wait! end
Makes the future fulfilled with ‘value`, which triggers all dependent futures.
@param [Object] value @!macro promise.param.raise_on_reassign @!macro promise.param.reserved
# File lib/concurrent-ruby/concurrent/promises.rb, line 1365 def fulfill(value, raise_on_reassign = true, reserved = false) resolve_with Fulfilled.new(value), raise_on_reassign, reserved end
Behaves as {Future#reason} but has one additional optional argument resolve_on_timeout.
@!macro promises.resolvable.resolve_on_timeout @return [Exception, timeout_value, nil] @see Future#reason
# File lib/concurrent-ruby/concurrent/promises.rb, line 1493 def reason(timeout = nil, timeout_value = nil, resolve_on_timeout = nil) if wait_until_resolved timeout internal_state.reason else if resolve_on_timeout unless resolve(*resolve_on_timeout, false) # if it fails to resolve it was resolved in the meantime # so return value as if there was no timeout return internal_state.reason end end timeout_value end end
Makes the future rejected with ‘reason`, which triggers all dependent futures.
@param [Object] reason @!macro promise.param.raise_on_reassign @!macro promise.param.reserved
# File lib/concurrent-ruby/concurrent/promises.rb, line 1375 def reject(reason, raise_on_reassign = true, reserved = false) resolve_with Rejected.new(reason), raise_on_reassign, reserved end
Makes the future resolved with result of triplet ‘fulfilled?`, `value`, `reason`, which triggers all dependent futures.
@param [true, false] fulfilled @param [Object] value @param [Object] reason @!macro promise.param.raise_on_reassign @!macro promise.param.reserved
# File lib/concurrent-ruby/concurrent/promises.rb, line 1355 def resolve(fulfilled = true, value = nil, reason = nil, raise_on_reassign = true, reserved = false) resolve_with(fulfilled ? Fulfilled.new(value) : Rejected.new(reason), raise_on_reassign, reserved) end
Behaves as {Future#result} but has one additional optional argument resolve_on_timeout.
@!macro promises.resolvable.resolve_on_timeout @return [::Array(Boolean, Object, Exception), nil] @see Future#result
# File lib/concurrent-ruby/concurrent/promises.rb, line 1514 def result(timeout = nil, resolve_on_timeout = nil) if wait_until_resolved timeout internal_state.result else if resolve_on_timeout unless resolve(*resolve_on_timeout, false) # if it fails to resolve it was resolved in the meantime # so return value as if there was no timeout internal_state.result end end # otherwise returns nil end end
Behaves as {Future#value} but has one additional optional argument resolve_on_timeout.
@!macro promises.resolvable.resolve_on_timeout @return [Object, timeout_value, nil] @see Future#value
# File lib/concurrent-ruby/concurrent/promises.rb, line 1449 def value(timeout = nil, timeout_value = nil, resolve_on_timeout = nil) if wait_until_resolved timeout internal_state.value else if resolve_on_timeout unless resolve(*resolve_on_timeout, false) # if it fails to resolve it was resolved in the meantime # so return value as if there was no timeout return internal_state.value end end timeout_value end end
Behaves as {Future#value!} but has one additional optional argument resolve_on_timeout.
@!macro promises.resolvable.resolve_on_timeout @return [Object, timeout_value, nil] @raise [Exception] {#reason} on rejection @see Future#value!
# File lib/concurrent-ruby/concurrent/promises.rb, line 1471 def value!(timeout = nil, timeout_value = nil, resolve_on_timeout = nil) if wait_until_resolved! timeout internal_state.value else if resolve_on_timeout unless resolve(*resolve_on_timeout, false) # if it fails to resolve it was resolved in the meantime # so return value as if there was no timeout raise self if rejected? return internal_state.value end end timeout_value end end
Behaves as {AbstractEventFuture#wait} but has one additional optional argument resolve_on_timeout.
@!macro promises.resolvable.resolve_on_timeout @return [self, true, false] @see AbstractEventFuture#wait
Concurrent::Promises::AbstractEventFuture#wait
# File lib/concurrent-ruby/concurrent/promises.rb, line 1411 def wait(timeout = nil, resolve_on_timeout = nil) super(timeout) or if resolve_on_timeout # if it fails to resolve it was resolved in the meantime # so return true as if there was no timeout !resolve(*resolve_on_timeout, false) else false end end
Behaves as {Future#wait!} but has one additional optional argument resolve_on_timeout.
@!macro promises.resolvable.resolve_on_timeout @return [self, true, false] @raise [Exception] {#reason} on rejection @see Future#wait!
Concurrent::Promises::Future#wait!
# File lib/concurrent-ruby/concurrent/promises.rb, line 1428 def wait!(timeout = nil, resolve_on_timeout = nil) super(timeout) or if resolve_on_timeout if resolve(*resolve_on_timeout, false) false else # if it fails to resolve it was resolved in the meantime # so return true as if there was no timeout raise self if rejected? true end else false end end