pub struct Context<M: Message, L = M> {
pub id: ActorId,
pub episode: Uuid,
/* private fields */
}Expand description
The ways out of an actor: what a Behavior may do besides answer.
A behavior owns one of these, and the actor keeps the mailbox, so messages reach the behavior one step at a time.
L is what this actor logs. It defaults to the message type, which is
what most actors log.
Fields§
§id: ActorIdThis actor’s name, as the other actors know it.
episode: UuidThe episode this actor is in, stamped on everything it logs.
Implementations§
Source§impl<M: Message, L> Context<M, L>
impl<M: Message, L> Context<M, L>
Sourcepub fn log(&self, payload: L)
pub fn log(&self, payload: L)
Log payload as an event stamped now. The event reaches the log when
this actor holds a logger and the log is listening; otherwise it is
dropped, and the actor carries on either way.
Sourcepub fn send(&self, message: M, to: HashSet<ActorId>) -> Result<()>
pub fn send(&self, message: M, to: HashSet<ActorId>) -> Result<()>
Send the statement message to every actor in to. An actor that
has already stopped is skipped. An actor may send to itself: the
message waits in its own mailbox for the current step to finish.
§Errors
Fails before anything is sent when to names an actor outside those
this one may send to.
Sourcepub async fn request(
&self,
message: M,
to: HashSet<ActorId>,
) -> Result<HashMap<ActorId, Vec<M>>>
pub async fn request( &self, message: M, to: HashSet<ActorId>, ) -> Result<HashMap<ActorId, Vec<M>>>
Ask every actor in to the same thing and collect their replies. A
recipient that has stopped, before or after receiving the request,
is left out of the result.
§Errors
Fails before anything is sent when to names an actor outside those
this one may send to, or names this actor itself, which is busy with this
very step.