pub struct Context<M> { /* private fields */ }Expand description
An execution context for a specific actor. Specifically, this is useful for managing
the lifecycle of itself (through the myself field) and other actors via the SystemHandle
provided using a dereference to BareContext.
A time-based deadline for receiving a message can be set using Self::set_deadline() and
friends.
Implementations§
Source§impl<M> Context<M>
impl<M> Context<M>
Sourcepub fn deadline(&self) -> &Option<Instant>
pub fn deadline(&self) -> &Option<Instant>
Get the deadline previously set using Self::set_deadline() or Self::set_timeout().
The deadline is cleared just before Actor::deadline_passed() is called.
Sourcepub fn set_deadline(&mut self, deadline: Option<Instant>)
pub fn set_deadline(&mut self, deadline: Option<Instant>)
Schedule a future one-shot call to Actor::deadline_passed(), or cancel the schedule.
A deadline in the past is considered to expire right in the next iteration (possibly after
receiving new messages).
Sourcepub fn set_timeout(&mut self, timeout: Option<Duration>)
pub fn set_timeout(&mut self, timeout: Option<Duration>)
Schedule or cancel a call to Actor::deadline_passed() after timeout from now.
Convenience variant of Self::set_deadline().
Methods from Deref<Target = BareContext<M>>§
Sourcepub fn subscribe<E: Event + Into<M>>(&self)
pub fn subscribe<E: Event + Into<M>>(&self)
Subscribe current actor to event of type E. This is part of the event system. You don’t
need to call this method to receive direct messages sent using Addr and Recipient.
Note that subscribing twice to the same event would result in duplicate events – no de-duplication of subscriptions is performed.
Sourcepub fn subscribe_and_receive_latest<E: Event + Into<M>>(
&self,
) -> Result<(), SendError>
pub fn subscribe_and_receive_latest<E: Event + Into<M>>( &self, ) -> Result<(), SendError>
Subscribe current actor to event of type E and send the last cached event to it.
This is part of the event system. You don’t need to call this method to receive
direct messages sent using Addr and Recipient.
Note that subscribing twice to the same event would result in duplicate events – no de-duplication of subscriptions is performed.
This method may fail if it is not possible to send the latest event. In this case it is guaranteed that the subscription did not take place. You can safely try again.