[−][src]Struct xtra::Context
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: Actor> Context<A>
[src]
pub fn new(message_cap: Option<usize>) -> (Address<A>, Self)
[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>, ActorShutdown>
[src]
Get an address to the current actor if the actor is not stopping or stopped.
pub async fn run(__arg0: Self, __arg1: 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,
act: &'_ mut A,
fut: F
) -> R where
F: Future<Output = R>,
[src]
&'_ mut self,
act: &'_ mut A,
fut: F
) -> R where
F: Future<Output = R>,
Handle any incoming messages for the actor while running a given future.
Example
pub fn notify<M>(&mut self, msg: M) where
M: Message,
A: Handler<M>,
[src]
M: Message,
A: Handler<M>,
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
M: Message + Clone + Sync,
A: Handler<M>,
[src]
M: Message + Clone + Sync,
A: Handler<M>,
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
F: Send + 'static + Fn() -> M,
M: Message,
A: Handler<M>,
[src]
&mut self,
duration: Duration,
constructor: F
) -> Result<impl Future<Output = ()>, ActorShutdown> where
F: Send + 'static + Fn() -> M,
M: Message,
A: Handler<M>,
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 Address
es). 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
M: Message,
A: Handler<M>,
[src]
&mut self,
duration: Duration,
notification: M
) -> Result<impl Future<Output = ()>, ActorShutdown> where
M: Message,
A: Handler<M>,
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>
impl<A> Send for Context<A>
impl<A> !Sync for Context<A>
impl<A> Unpin for Context<A>
impl<A> !UnwindSafe for Context<A>
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,