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

&(other)
Alias for: zip
any(event_or_future) click to toggle source

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
Also aliased as: |
delay() click to toggle source

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
schedule(intended_time) click to toggle source

@!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
to_event() click to toggle source

Returns self, since this is event @return [Event]

# File lib/concurrent-ruby/concurrent/promises.rb, line 883
def to_event
  self
end
to_future() click to toggle source

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
with_default_executor(executor) click to toggle source

@!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
zip(other) click to toggle source

@!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
Also aliased as: &
|(event_or_future)
Alias for: any

Private Instance Methods

callback_on_resolution(state, args, callback) click to toggle source
# File lib/concurrent-ruby/concurrent/promises.rb, line 900
def callback_on_resolution(state, args, callback)
  callback.call(*args)
end
rejected_resolution(raise_on_reassign, state) click to toggle source
# 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