Trait simpl_actor::ActorRef

source ·
pub trait ActorRef {
    // Required methods
    fn stop_gracefully<'life0, 'async_trait>(
        &'life0 self
    ) -> Pin<Box<dyn Future<Output = Result<(), ActorError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn stop_immediately(&self);
    fn wait_for_stop<'life0, 'async_trait>(
        &'life0 self
    ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
}
Expand description

Provides functionality to stop and wait for an actor to complete based on an actor ref.

Required Methods§

source

fn stop_gracefully<'life0, 'async_trait>( &'life0 self ) -> Pin<Box<dyn Future<Output = Result<(), ActorError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Signals the actor to stop after processing all messages currently in its mailbox.

This method sends a special stop message to the end of the actor’s mailbox, ensuring that the actor will process all preceding messages before stopping. Any messages sent after this stop signal will be ignored and dropped. This approach allows for a graceful shutdown of the actor, ensuring all pending work is completed before termination.

source

fn stop_immediately(&self)

Signals the actor to stop immediately, bypassing its mailbox.

This method instructs the actor to terminate as soon as it finishes processing the current message, if any. Messages in the mailbox that have not yet been processed will be ignored and dropped. This method is useful for immediate shutdown scenarios where waiting for the mailbox to empty is not feasible or desired.

Note: If the actor is in the middle of processing a message, it will complete that message before stopping.

source

fn wait_for_stop<'life0, 'async_trait>( &'life0 self ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Waits for the actor to finish processing and stop.

This method suspends execution until the actor has stopped, ensuring that any ongoing processing is completed and the actor has fully terminated. This is particularly useful in scenarios where it’s necessary to wait for an actor to clean up its resources or complete its final tasks before proceeding.

Note: This method does not initiate the stop process; it only waits for the actor to stop. You should signal the actor to stop using stop_gracefully or stop_immediately before calling this method.

§Examples
// Assuming `actor.stop_gracefully().await` has been called earlier
actor.wait_for_stop().await;

Implementors§