pub struct Context<E: Event> { /* private fields */ }Expand description
Runtime-provided context for an actor to interact with the system.
Use it to:
send(event): emit events into the broker tagged with this actor’s namestop(): request graceful shutdown of this actor (and trigger global cancel)name(): retrieve the actor’s name for logging/identityis_alive(): check whether the actor loop should continue running
Correlation:
send_with_correlation(event, id): emit an event linked to a specific correlation id.send_child_event(event, meta): convenience to set correlation id to the parentmeta.id().
See also: Envelope, Meta, crate::Supervisor.
Implementations§
Source§impl<E: Event> Context<E>
impl<E: Event> Context<E>
pub fn new( actor_id: ActorId, sender: Sender<Arc<Envelope<E>>>, alive: Arc<AtomicBool>, ) -> Self
Sourcepub async fn send(&self, event: E) -> Result<()>
pub async fn send(&self, event: E) -> Result<()>
Send an event to the broker. The envelope will carry this actor’s name. This awaits channel capacity (backpressure) to avoid silent drops.
Sourcepub async fn send_with_correlation(
&self,
event: E,
correlation_id: EventId,
) -> Result<()>
pub async fn send_with_correlation( &self, event: E, correlation_id: EventId, ) -> Result<()>
Send an event with an explicit correlation id.
Sourcepub async fn send_child_event(&self, event: E, meta: &Meta) -> Result<()>
pub async fn send_child_event(&self, event: E, meta: &Meta) -> Result<()>
Emit a child event correlated to the given parent Meta.
pub async fn send_envelope(&self, envelope: Envelope<E>) -> Result<()>
pub fn actor_id(&self) -> &ActorId
Sourcepub fn actor_name(&self) -> &str
pub fn actor_name(&self) -> &str
The actor’s name as registered with the supervisor.
Sourcepub async fn pending(&self) -> Result<()>
pub async fn pending(&self) -> Result<()>
Returns a future that never completes.
Note: This method is largely obsolete. The default step() implementation
now returns StepAction::Never, which disables stepping entirely. You only need
pending() if you want to block inside a custom step() implementation.
ⓘ
// Prefer this (default behavior):
async fn step(&mut self) -> Result<StepAction> {
Ok(StepAction::Never)
}
// Or simply don't implement step() at all - it defaults to NeverTrait Implementations§
Auto Trait Implementations§
impl<E> Freeze for Context<E>
impl<E> RefUnwindSafe for Context<E>
impl<E> Send for Context<E>
impl<E> Sync for Context<E>
impl<E> Unpin for Context<E>
impl<E> UnwindSafe for Context<E>
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