class Concurrent::Promises::ResolvableFuture
A Future
which can be resolved by user.
Public Instance Methods
Source
# File lib/concurrent-ruby/concurrent/promises.rb, line 1384 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]
Source
# File lib/concurrent-ruby/concurrent/promises.rb, line 1395 def evaluate_to!(*args, &block) promise.evaluate_to(*args, block).wait! 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.
Source
# File lib/concurrent-ruby/concurrent/promises.rb, line 1364 def fulfill(value, raise_on_reassign = true, reserved = false) resolve_with Fulfilled.new(value), raise_on_reassign, reserved 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
Source
# File lib/concurrent-ruby/concurrent/promises.rb, line 1492 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
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
Source
# File lib/concurrent-ruby/concurrent/promises.rb, line 1374 def reject(reason, raise_on_reassign = true, reserved = false) resolve_with Rejected.new(reason), raise_on_reassign, reserved 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
Source
# File lib/concurrent-ruby/concurrent/promises.rb, line 1354 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
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
Source
# File lib/concurrent-ruby/concurrent/promises.rb, line 1513 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#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
Source
# File lib/concurrent-ruby/concurrent/promises.rb, line 1448 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] @see Future#value
Source
# File lib/concurrent-ruby/concurrent/promises.rb, line 1470 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 {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!
Source
# File lib/concurrent-ruby/concurrent/promises.rb, line 1410 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 {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
Source
# File lib/concurrent-ruby/concurrent/promises.rb, line 1427 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
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!