class Concurrent::Promises::Event
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.
Public Instance Methods
Creates a new event which will be resolved when the first of receiver, ‘event_or_future` resolves.
@return [Event]
# File lib/concurrent-ruby/concurrent/promises.rb, line 843 def any(event_or_future) AnyResolvedEventPromise.new_blocked_by2(self, event_or_future, @DefaultExecutor).event end
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.
@return [Event]
# File lib/concurrent-ruby/concurrent/promises.rb, line 853 def delay event = DelayPromise.new(@DefaultExecutor).event ZipEventEventPromise.new_blocked_by2(self, event, @DefaultExecutor).event end
@!macro promise.method.schedule
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. @!macro promises.param.intended_time
@return [Event]
# File lib/concurrent-ruby/concurrent/promises.rb, line 865 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
Returns self, since this is event @return [Event]
# File lib/concurrent-ruby/concurrent/promises.rb, line 883 def to_event self end
Converts event to a future. The future is fulfilled when the event is resolved, the future may never fail.
@return [Future]
# File lib/concurrent-ruby/concurrent/promises.rb, line 875 def to_future future = Promises.resolvable_future ensure chain_resolvable(future) end
@!macro promises.method.with_default_executor @return [Event]
# File lib/concurrent-ruby/concurrent/promises.rb, line 889 def with_default_executor(executor) EventWrapperPromise.new_blocked_by1(self, executor).event end
@!macro promises.method.zip
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}.
@return [Future, Event]
# File lib/concurrent-ruby/concurrent/promises.rb, line 829 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
Private Instance Methods
# File lib/concurrent-ruby/concurrent/promises.rb, line 900 def callback_on_resolution(state, args, callback) callback.call(*args) end
# File lib/concurrent-ruby/concurrent/promises.rb, line 895 def rejected_resolution(raise_on_reassign, state) raise Concurrent::MultipleAssignmentError.new('Event can be resolved only once') if raise_on_reassign return false end