Class: Concurrent::Promises::ResolvableFuture
Relationships & Source Files | |
Super Chains via Extension / Inclusion / Inheritance | |
Class Chain:
|
|
Instance Chain:
|
|
Inherits: |
Concurrent::Promises::Future
|
Defined in: | lib/concurrent-ruby/concurrent/promises.rb |
Overview
A Future which can be resolved by user.
Constant Summary
InternalStates
- Included
Class Attribute Summary
Synchronization::Object
- Inherited
Class Method Summary
AbstractEventFuture
- Inherited
Synchronization::Object
- Inherited
.atomic_attribute?, .atomic_attributes, | |
.attr_atomic | Creates methods for reading and writing to a instance variable with volatile (Java) semantic as |
.attr_volatile | Creates methods for reading and writing (as |
.ensure_safe_initialization_when_final_fields_are_present | For testing purposes, quite slow. |
.new | Has to be called by children. |
.safe_initialization!, .define_initialize_atomic_fields |
Synchronization::AbstractObject
- Inherited
Instance Attribute Summary
Future
- Inherited
#fulfilled? | Is it in fulfilled state? |
#rejected? | Is it in rejected state? |
AbstractEventFuture
- Inherited
#pending? | Is it in pending state? |
#resolved? | Is it in resolved state? |
#touched? | For inspection. |
Instance Method Summary
-
#evaluate_to(*args) {|*args| ... } ⇒ self
Evaluates the block and sets its result as future’s value fulfilling, if the block raises an exception the future rejects with it.
-
#evaluate_to!(*args) {|*args| ... } ⇒ self
Evaluates the block and sets its result as future’s value fulfilling, if the block raises an exception the future rejects with it.
-
#fulfill(value, raise_on_reassign = true, reserved = false) ⇒ self, false
Makes the future fulfilled with #value, which triggers all dependent futures.
-
#reason(timeout = nil, timeout_value = nil, resolve_on_timeout = nil) ⇒ Exception, ...
Behaves as Future#reason but has one additional optional argument resolve_on_timeout.
-
#reject(reason, raise_on_reassign = true, reserved = false) ⇒ self, false
Makes the future rejected with #reason, which triggers all dependent futures.
- #resolve(fulfilled = true, value = nil, reason = nil, raise_on_reassign = true, reserved = false) ⇒ self, false
-
#result(timeout = nil, resolve_on_timeout = nil) ⇒ ::Array(Boolean, Object, Exception)?
Behaves as Future#result but has one additional optional argument resolve_on_timeout.
-
#value(timeout = nil, timeout_value = nil, resolve_on_timeout = nil) ⇒ Object, ...
Behaves as Future#value but has one additional optional argument resolve_on_timeout.
-
#value!(timeout = nil, timeout_value = nil, resolve_on_timeout = nil) ⇒ Object, ...
Behaves as Future#value! but has one additional optional argument resolve_on_timeout.
-
#wait(timeout = nil, resolve_on_timeout = nil) ⇒ self, ...
Behaves as AbstractEventFuture#wait but has one additional optional argument resolve_on_timeout.
-
#wait!(timeout = nil, resolve_on_timeout = nil) ⇒ self, ...
Behaves as Future#wait! but has one additional optional argument resolve_on_timeout.
-
#with_hidden_resolvable ⇒ Future
Creates new future wrapping receiver, effectively hiding the resolve method and similar.
Resolvable
- Included
#release, | |
#reserve | Reserves the event or future, if reserved others are prevented from resolving it. |
Future
- Inherited
#& | Alias for Future#zip. |
#any | Creates a new event which will be resolved when the first of receiver, |
#delay | Creates new future dependent on receiver which will not evaluate until touched, see |
#exception | Allows rejected |
#flat | Alias for Future#flat_future. |
#flat_event | Creates new event which will be resolved when the returned event by receiver is. |
#flat_future | Creates new future which will have result of the future returned by receiver. |
#inspect | Alias for Future#to_s. |
#on_fulfillment | Shortcut of |
#on_fulfillment! | Stores the callback to be executed synchronously on resolving thread after it is fulfilled. |
#on_fulfillment_using | Stores the callback to be executed asynchronously on executor after it is fulfilled. |
#on_rejection | Shortcut of |
#on_rejection! | Stores the callback to be executed synchronously on resolving thread after it is rejected. |
#on_rejection_using | Stores the callback to be executed asynchronously on executor after it is rejected. |
#reason | Returns reason of future’s rejection. |
#rescue | Shortcut of |
#rescue_on | Chains the task to be executed asynchronously on executor after it rejects. |
#result | Returns triplet fulfilled?, value, reason. |
#run | Allows to use futures as green threads. |
#schedule | Creates new event dependent on receiver scheduled to execute on/in intended_time. |
#then | Shortcut of |
#then_on | Chains the task to be executed asynchronously on executor after it fulfills. |
#to_event | Converts future to event which is resolved when future is resolved by fulfillment or rejection. |
#to_future | Returns self, since this is a future. |
#to_s, | |
#value | Return value of the future. |
#value! | Return value of the future. |
#wait! | Wait (block the Thread) until receiver is |
#with_default_executor | Crates new object with same class with the executor set as its new default executor. |
#zip | Creates a new event or a future which will be resolved when receiver and other are. |
#| | Alias for Future#any. |
#apply, #async_callback_on_fulfillment, #async_callback_on_rejection, #callback_on_fulfillment, #callback_on_rejection, #callback_on_resolution, #rejected_resolution, #run_test, #wait_until_resolved! |
Future::OldChannelIntegration
- Included
#then_put, | |
#then_select | Zips with selected value form the suplied channels. |
Future::NewChannelIntegration
- Included
Future::FlatShortcuts
- Included
Future::ActorIntegration
- Included
#then_ask | Asks the actor with its value. |
AbstractEventFuture
- Inherited
#chain | Shortcut of |
#chain_on | Chains the task to be executed asynchronously on executor after it is resolved. |
#chain_resolvable | Resolves the resolvable when receiver is resolved. |
#default_executor | Returns default executor. |
#inspect | Alias for AbstractEventFuture#to_s. |
#internal_state, | |
#on_resolution | Shortcut of |
#on_resolution! | Stores the callback to be executed synchronously on resolving thread after it is resolved. |
#on_resolution_using | Stores the callback to be executed asynchronously on executor after it is resolved. |
#state | Returns its state. |
#tangle | Alias for AbstractEventFuture#chain_resolvable. |
#to_s, | |
#touch | Propagates touch. |
#wait | Wait (block the Thread) until receiver is |
#with_default_executor | Crates new object with same class with the executor set as its new default executor. |
#add_callback, #add_callback_clear_delayed_node, #add_callback_notify_blocked, #async_callback_on_resolution, | |
#blocks | For inspection. |
#call_callback, #call_callbacks, #callback_clear_delayed_node, #callback_notify_blocked, | |
#callbacks | For inspection. |
#compare_and_set_internal_state | Sets the internal_state to new_internal_state if the current internal_state is expected_internal_state. |
#internal_state= |
|
#promise | For inspection. |
#resolve_with, | |
#swap_internal_state |
|
#update_internal_state | Updates the internal_state using the block. |
#wait_until_resolved, | |
#waiting_threads | For inspection. |
#with_async, #with_hidden_resolvable |
Synchronization::Object
- Inherited
Synchronization::Volatile
- Included
Synchronization::AbstractObject
- Inherited
Constructor Details
This class inherits a constructor from Concurrent::Promises::AbstractEventFuture
Instance Method Details
#evaluate_to(*args) {|*args| ... } ⇒ self
Evaluates the block and sets its result as future’s value fulfilling, if the block raises an exception the future rejects with it.
# File 'lib/concurrent-ruby/concurrent/promises.rb', line 1395
def evaluate_to(*args, &block) promise.evaluate_to(*args, block) end
#evaluate_to!(*args) {|*args| ... } ⇒ self
Evaluates the block and sets its result as future’s value fulfilling, if the block raises an exception the future rejects with it.
# File 'lib/concurrent-ruby/concurrent/promises.rb', line 1406
def evaluate_to!(*args, &block) promise.evaluate_to(*args, block).wait! end
#fulfill(value, raise_on_reassign = true, reserved = false) ⇒ self
, false
Makes the future fulfilled with #value, which triggers all dependent futures.
#reason(timeout = nil, timeout_value = nil, resolve_on_timeout = nil) ⇒ Exception
, ...
Behaves as Future#reason but has one additional optional argument resolve_on_timeout.
# File 'lib/concurrent-ruby/concurrent/promises.rb', line 1503
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
#reject(reason, raise_on_reassign = true, reserved = false) ⇒ self
, false
Makes the future rejected with #reason, which triggers all dependent futures.
#resolve(fulfilled = true, value = nil, reason = nil, raise_on_reassign = true, reserved = false) ⇒ self
, false
#result(timeout = nil, resolve_on_timeout = nil) ⇒ ::Array
(Boolean
, Object, Exception
)?
Behaves as Future#result but has one additional optional argument resolve_on_timeout.
# File 'lib/concurrent-ruby/concurrent/promises.rb', line 1524
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
#value(timeout = nil, timeout_value = nil, resolve_on_timeout = nil) ⇒ Object, ...
Behaves as Future#value but has one additional optional argument resolve_on_timeout.
# File 'lib/concurrent-ruby/concurrent/promises.rb', line 1459
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
#value!(timeout = nil, timeout_value = nil, resolve_on_timeout = nil) ⇒ Object, ...
Behaves as Future#value! but has one additional optional argument resolve_on_timeout.
# File 'lib/concurrent-ruby/concurrent/promises.rb', line 1481
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
#wait(timeout = nil, resolve_on_timeout = nil) ⇒ self
, ...
Behaves as AbstractEventFuture#wait but has one additional optional argument resolve_on_timeout.
# File 'lib/concurrent-ruby/concurrent/promises.rb', line 1421
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
#wait!(timeout = nil, resolve_on_timeout = nil) ⇒ self
, ...
Behaves as Future#wait! but has one additional optional argument resolve_on_timeout.
# File 'lib/concurrent-ruby/concurrent/promises.rb', line 1438
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