Class: Concurrent::Promises::Event
- Inherits:
-
AbstractEventFuture
- Object
- Synchronization::Object
- AbstractEventFuture
- Concurrent::Promises::Event
- Defined in:
- lib/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.
Direct Known Subclasses
Instance Method Summary collapse
-
#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 AbstractEventFuture#touch.
-
#schedule(intended_time) ⇒ Event
Creates new event dependent on receiver scheduled to execute on/in intended_time.
-
#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.
Instance Method Details
#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.
842 843 844 |
# File 'lib/concurrent/promises.rb', line 842 def any(event_or_future) AnyResolvedEventPromise.new_blocked_by2(self, event_or_future, @DefaultExecutor).event end |
#delay ⇒ Event
Creates new event dependent on receiver which will not evaluate until touched, see AbstractEventFuture#touch. In other words, it inserts delay into the chain of Futures making rest of it lazy evaluated.
852 853 854 855 |
# File 'lib/concurrent/promises.rb', line 852 def delay event = DelayPromise.new(@DefaultExecutor).event ZipEventEventPromise.new_blocked_by2(self, event, @DefaultExecutor).event 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.
864 865 866 867 868 869 |
# File 'lib/concurrent/promises.rb', line 864 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 |
#to_event ⇒ Event
Returns self, since this is event
882 883 884 |
# File 'lib/concurrent/promises.rb', line 882 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.
874 875 876 877 878 |
# File 'lib/concurrent/promises.rb', line 874 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.
888 889 890 |
# File 'lib/concurrent/promises.rb', line 888 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.
828 829 830 831 832 833 834 |
# File 'lib/concurrent/promises.rb', line 828 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 |