Struct xtra::prelude::Context

source ·
pub struct Context<A: Actor> { /* private fields */ }
Expand description

Context is used to control how the actor is managed and to get the actor’s address from inside of a message handler.

Implementations§

Creates a new actor context with a given mailbox capacity, returning an address to the actor and the context. This can be used as a builder to add more actors to an address before any have started.

Example
let (addr, mut ctx) = Context::new(Some(32));
for n in 0..3 {
    smol::spawn(ctx.attach(MyActor::new(n))).detach();
}
ctx.run(MyActor::new(4)).await;

Attaches an actor of the same type listening to the same address as this actor is. They will operate in a message-stealing fashion, with no message handled by two actors.

Stop the actor as soon as it has finished processing current message. This will mean that the Actor::stopping method will be called.

Get an address to the current actor if there are still external addresses to the actor.

Run the given actor’s main loop, handling incoming messages to its mailbox.

Yields to the manager to handle one message.

Handle any incoming messages for the actor while running a given future.

Example

Notify this actor with a message that is handled before any other messages from the general queue are processed (therefore, immediately). If multiple notify messages are queued, they will still be processed in the order that they are queued (i.e the immediate priority is only over other messages).

Notify all actors on this address actor with a message that is handled after any other messages from the general queue are processed.

Notify the actor with a synchronously handled message every interval until it is stopped (either directly with Context::stop, or for a lack of strong Addresses). This does not take priority over other messages.

Notify the actor with a synchronously handled message after a certain duration has elapsed. This does not take priority over other messages.

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.