Class: Concurrent::Promises::Event
Relationships & Source Files | |
Extension / Inclusion / Inheritance Descendants | |
Subclasses:
|
|
Super Chains via Extension / Inclusion / Inheritance | |
Class Chain:
|
|
Instance Chain:
|
|
Inherits: | Concurrent::Promises::AbstractEventFuture |
Defined in: | lib/concurrent-ruby/concurrent/promises.rb |
Overview
Represents an event which will happen in future (will be resolved). The event is either pending or resolved. It should be always resolved. Use Future
to communicate rejections and cancellation.
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
AbstractEventFuture
- Inherited
#pending? | Is it in pending state? |
#resolved? | Is it in resolved state? |
#touched? | For inspection. |
Instance Method Summary
-
#&(other)
Alias for #zip.
-
#any(event_or_future) ⇒ Event
(also: #|)
Creates a new event which will be resolved when the first of receiver,
event_or_future
resolves. -
#delay ⇒ Event
Creates new event dependent on receiver which will not evaluate until touched, see
#touch
. -
#schedule(intended_time) ⇒ Event
Creates new event dependent on receiver scheduled to execute on/in intended_time.
-
#then(*args, &task)
Alias for AbstractEventFuture#chain.
-
#to_event ⇒ Event
Returns self, since this is event.
-
#to_future ⇒ Future
Converts event to a future.
-
#with_default_executor(executor) ⇒ Event
Crates new object with same class with the executor set as its new default executor.
-
#zip(other) ⇒ Future, Event
(also: #&)
Creates a new event or a future which will be resolved when receiver and other are.
-
#|(event_or_future)
Alias for #any.
- #callback_on_resolution(state, args, callback) private
- #rejected_resolution(raise_on_reassign, state) private
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
#&(other)
Alias for #zip.
# File 'lib/concurrent-ruby/concurrent/promises.rb', line 847
alias_method :&, :zip
#any(event_or_future) ⇒ Event
Also known as: #|
Creates a new event which will be resolved when the first of receiver, event_or_future
resolves.
# File 'lib/concurrent-ruby/concurrent/promises.rb', line 853
def any(event_or_future) AnyResolvedEventPromise.new_blocked_by2(self, event_or_future, @DefaultExecutor).event end
#callback_on_resolution(state, args, callback) (private)
[ GitHub ]# File 'lib/concurrent-ruby/concurrent/promises.rb', line 910
def callback_on_resolution(state, args, callback) callback.call(*args) end
#delay ⇒ Event
Creates new event dependent on receiver which will not evaluate until touched, see #touch
. In other words, it inserts delay into the chain of Futures making rest of it lazy evaluated.
# File 'lib/concurrent-ruby/concurrent/promises.rb', line 863
def delay event = DelayPromise.new(@DefaultExecutor).event ZipEventEventPromise.new_blocked_by2(self, event, @DefaultExecutor).event end
#rejected_resolution(raise_on_reassign, state) (private)
# File 'lib/concurrent-ruby/concurrent/promises.rb', line 905
def rejected_resolution(raise_on_reassign, state) raise Concurrent::MultipleAssignmentError.new('Event can be resolved only once') if raise_on_reassign return false end
#schedule(intended_time) ⇒ Event
Creates new event dependent on receiver scheduled to execute on/in intended_time. In time is interpreted from the moment the receiver is resolved, therefore it inserts delay into the chain.
# File 'lib/concurrent-ruby/concurrent/promises.rb', line 875
def schedule(intended_time) chain do event = ScheduledPromise.new(@DefaultExecutor, intended_time).event ZipEventEventPromise.new_blocked_by2(self, event, @DefaultExecutor).event end.flat_event end
#then(*args, &task)
Alias for AbstractEventFuture#chain.
# File 'lib/concurrent-ruby/concurrent/promises.rb', line 828
alias_method :then, :chain
#to_event ⇒ Event
Returns self, since this is event
# File 'lib/concurrent-ruby/concurrent/promises.rb', line 893
def to_event self end
#to_future ⇒ Future
Converts event to a future. The future is fulfilled when the event is resolved, the future may never fail.
# File 'lib/concurrent-ruby/concurrent/promises.rb', line 885
def to_future future = Promises.resolvable_future ensure chain_resolvable(future) end
#with_default_executor(executor) ⇒ Event
Crates new object with same class with the executor set as its new default executor. Any futures depending on it will use the new default executor.
# File 'lib/concurrent-ruby/concurrent/promises.rb', line 899
def with_default_executor(executor) EventWrapperPromise.new_blocked_by1(self, executor).event end
#zip(other) ⇒ Future, Event
Also known as: #&
Creates a new event or a future which will be resolved when receiver and other are. Returns an event if receiver and other are events, otherwise returns a future. If just one of the parties is Future
then the result of the returned future is equal to the result of the supplied future. If both are futures then the result is as described in FactoryMethods#zip_futures_on.
# File 'lib/concurrent-ruby/concurrent/promises.rb', line 839
def zip(other) if other.is_a?(Future) ZipFutureEventPromise.new_blocked_by2(other, self, @DefaultExecutor).future else ZipEventEventPromise.new_blocked_by2(self, other, @DefaultExecutor).event end end
#|(event_or_future)
Alias for #any.
# File 'lib/concurrent-ruby/concurrent/promises.rb', line 857
alias_method :|, :any