[][src]Struct xtra_addons::Context

pub struct Context<A> where
    A: Actor
{ /* fields omitted */ }

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

Implementations

impl<A> Context<A> where
    A: Actor
[src]

pub fn new(message_cap: Option<usize>) -> (Address<A, Strong>, Context<A>)[src]

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;

pub fn attach(&mut self, actor: A) -> impl Future<Output = ()>[src]

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.

pub fn stop(&mut self)[src]

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

pub fn address(&self) -> Result<Address<A, Strong>, ActorShutdown>[src]

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

pub async fn run(self, actor: A)[src]

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

pub async fn yield_once(&'_ mut self, act: &'_ mut A)[src]

Yields to the manager to handle one message.

pub async fn handle_while<F, R>(&'_ mut self, actor: &'_ mut A, fut: F) -> R where
    F: Future<Output = R>, 
[src]

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

Example

pub fn notify<M>(&mut self, msg: M) where
    A: Handler<M>,
    M: Message
[src]

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).

pub fn notify_all<M>(&mut self, msg: M) where
    A: Handler<M>,
    M: Message + Clone + Sync
[src]

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

pub fn notify_interval<F, M>(
    &mut self,
    duration: Duration,
    constructor: F
) -> Result<impl Future<Output = ()>, ActorShutdown> where
    A: Handler<M>,
    M: Message,
    F: Send + 'static + Fn() -> M, 
[src]

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.

pub fn notify_after<M>(
    &mut self,
    duration: Duration,
    notification: M
) -> Result<impl Future<Output = ()>, ActorShutdown> where
    A: Handler<M>,
    M: Message
[src]

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

impl<A> !RefUnwindSafe for Context<A>[src]

impl<A> Send for Context<A>[src]

impl<A> !Sync for Context<A>[src]

impl<A> Unpin for Context<A>[src]

impl<A> !UnwindSafe for Context<A>[src]

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.