pub struct Context<M> { /* private fields */ }Expand description
Context provided to actors during execution.
Provides access to:
- Self reference (to give to other actors)
- Actor system (to spawn child actors and run compute)
- Cancellation (for graceful shutdown)
Implementations§
Source§impl<M: Send + 'static> Context<M>
impl<M: Send + 'static> Context<M>
Sourcepub fn system(&self) -> &ActorSystem
pub fn system(&self) -> &ActorSystem
Get the actor system (for spawning child actors).
Sourcepub fn is_cancelled(&self) -> bool
pub fn is_cancelled(&self) -> bool
Check if shutdown was requested.
Sourcepub fn cancellation_token(&self) -> CancellationToken
pub fn cancellation_token(&self) -> CancellationToken
Get the cancellation token.
Source§impl<M: Send + 'static> Context<M>
impl<M: Send + 'static> Context<M>
Sourcepub fn schedule_once<F: FnOnce() -> M + Send + 'static>(
&self,
delay: Duration,
factory: F,
) -> TimerHandle
pub fn schedule_once<F: FnOnce() -> M + Send + 'static>( &self, delay: Duration, factory: F, ) -> TimerHandle
Schedule a message to be sent to this actor after a delay.
Uses a factory function to create the message, so M doesn’t need to be Clone.
Returns a handle that can be used to cancel the timer.
Source§impl<M: Send + Sync + Clone + 'static> Context<M>
impl<M: Send + Sync + Clone + 'static> Context<M>
Sourcepub fn schedule_repeat(&self, interval: Duration, msg: M) -> TimerHandle
pub fn schedule_repeat(&self, interval: Duration, msg: M) -> TimerHandle
Schedule a message to be sent to this actor repeatedly at an interval.
The timer continues until cancelled or the actor is dropped. Returns a handle that can be used to cancel the timer.
Trait Implementations§
Auto Trait Implementations§
impl<M> Freeze for Context<M>
impl<M> !RefUnwindSafe for Context<M>
impl<M> Send for Context<M>where
M: Send,
impl<M> Sync for Context<M>where
M: Send,
impl<M> Unpin for Context<M>
impl<M> UnsafeUnpin for Context<M>
impl<M> !UnwindSafe for Context<M>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more