ActorContext

Struct ActorContext 

Source
pub struct ActorContext<A: Actor> { /* private fields */ }

Implementations§

Source§

impl<A: Actor> ActorContext<A>

Source

pub fn spawn_ctx(&self) -> &SpawnContext

Source

pub async fn sleep(&self, duration: Duration)

Sleeps for a given amount of time.

That sleep is measured by the universe scheduler, which means that it can be shortened if Universe::simulate_sleep(..) is used.

While sleeping, an actor is NOT protected from its supervisor. It is up to the user to call ActorContext::protect_future(..).

Source

pub fn mailbox(&self) -> &Mailbox<A>

Source

pub fn actor_instance_id(&self) -> &str

Source

pub fn protect_zone(&self) -> ProtectedZoneGuard

This function returns a guard that prevents any supervisor from identifying the actor as dead. The protection ends when the ProtectZoneGuard is dropped.

In an ideal world, you should never need to call this function. It is only useful in some corner cases, like calling a long blocking from an external library that you trust.

Source

pub async fn protect_future<Fut, T>(&self, future: Fut) -> T
where Fut: Future<Output = T>,

Executes a future in a protected zone.

Source

pub async fn yield_now(&self)

Cooperatively yields, while keeping the actor protected.

Source

pub fn kill_switch(&self) -> &KillSwitch

Gets a copy of the actor kill switch. This should rarely be used.

For instance, when quitting from the process_message function, prefer simply returning Error(ActorExitStatus::Failure(..))

Source

pub fn progress(&self) -> &Progress

Source

pub fn spawn_actor<SpawnedActor: Actor>(&self) -> SpawnBuilder<SpawnedActor>

Source

pub fn record_progress(&self)

Records some progress. This function is only useful when implementing actors that may take more than HEARTBEAT to process a single message. In that case, you can call this function in the middle of the process_message method to prevent the actor from being identified as blocked or dead.

Source

pub async fn send_message<DestActor, M>( &self, mailbox: &Mailbox<DestActor>, msg: M, ) -> Result<Receiver<DestActor::Reply>, SendError>
where DestActor: DeferableReplyHandler<M> + Actor, M: 'static + Send + Sync + Debug,

Posts a message in an actor’s mailbox.

This method does not wait for the message to be handled by the target actor. However, it returns a oneshot receiver that the caller that makes it possible to .await it. If the reply is important, chances are the .ask(...) method is more indicated.

Droppping the receiver channel will not cancel the processing of the message. It is a very common usage. In fact most actors are expected to send message in a fire-and-forget fashion.

Regular messages (as opposed to commands) are queued and guaranteed to be processed in FIFO order.

This method hides logic to prevent an actor from being identified as frozen if the destination actor channel is saturated, and we are simply experiencing back pressure.

Source

pub async fn ask<DestActor, M, T>( &self, mailbox: &Mailbox<DestActor>, msg: M, ) -> Result<T, AskError<Infallible>>
where DestActor: DeferableReplyHandler<M, Reply = T> + Actor, M: 'static + Send + Sync + Debug,

Source

pub async fn ask_for_res<DestActor, M, T, E>( &self, mailbox: &Mailbox<DestActor>, msg: M, ) -> Result<T, AskError<E>>
where DestActor: DeferableReplyHandler<M, Reply = Result<T, E>> + Actor, M: Debug + Send + Sync + 'static, E: Debug,

Similar to send_message, except this method waits asynchronously for the actor reply.

Source

pub async fn send_exit_with_success<Dest: Actor>( &self, mailbox: &Mailbox<Dest>, ) -> Result<(), SendError>

Send the Success message to terminate the destination actor with the Success exit status.

The message is queued like any regular message, so that pending messages will be processed first.

Source

pub async fn send_self_message<M>( &self, msg: M, ) -> Result<Receiver<A::Reply>, SendError>
where A: DeferableReplyHandler<M>, M: 'static + Sync + Send + Debug,

Sends a message to an actor’s own mailbox.

Warning: This method is dangerous as it can very easily cause a deadlock.

Source

pub fn try_send_self_message<M>( &self, msg: M, ) -> Result<Receiver<A::Reply>, TrySendError<M>>
where A: DeferableReplyHandler<M>, M: 'static + Sync + Send + Debug,

Attempts to send a message to itself. The message will be queue to self’s low_priority queue.

Warning: This method will always fail if an actor has a capacity of 0.

Source

pub async fn schedule_self_msg<M>(&self, after_duration: Duration, message: M)
where A: DeferableReplyHandler<M>, M: Sync + Send + Debug + 'static,

Schedules a message that will be sent to the high-priority queue of the actor Mailbox once after_duration has elapsed.

Trait Implementations§

Source§

impl<A: Actor> Clone for ActorContext<A>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<A: Actor> Deref for ActorContext<A>

Source§

type Target = ActorContextInner<A>

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.

Auto Trait Implementations§

§

impl<A> Freeze for ActorContext<A>

§

impl<A> RefUnwindSafe for ActorContext<A>

§

impl<A> Send for ActorContext<A>

§

impl<A> Sync for ActorContext<A>

§

impl<A> Unpin for ActorContext<A>

§

impl<A> UnwindSafe for ActorContext<A>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more