Trait simpl_actor::ActorRef
source · pub trait ActorRef: Clone + Send + Sync {
// Required methods
fn id(&self) -> u64;
fn is_alive(&self) -> bool;
fn link_child<'life0, 'life1, 'async_trait, R>(
&'life0 self,
child: &'life1 R
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where R: 'async_trait + ActorRef,
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
fn unlink_child<'life0, 'life1, 'async_trait, R>(
&'life0 self,
child: &'life1 R
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where R: 'async_trait + ActorRef,
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
fn link_together<'life0, 'life1, 'async_trait, R>(
&'life0 self,
actor_ref: &'life1 R
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where R: 'async_trait + ActorRef,
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
fn unlink_together<'life0, 'life1, 'async_trait, R>(
&'life0 self,
actor_ref: &'life1 R
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where R: 'async_trait + ActorRef,
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
fn notify_link_died<'life0, 'async_trait>(
&'life0 self,
id: u64,
reason: ActorStopReason
) -> Pin<Box<dyn Future<Output = Result<(), ActorError>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
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.
This trait is automatically implemented by the actor macro.
Required Methods§
sourcefn link_child<'life0, 'life1, 'async_trait, R>(
&'life0 self,
child: &'life1 R
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
R: 'async_trait + ActorRef,
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn link_child<'life0, 'life1, 'async_trait, R>(
&'life0 self,
child: &'life1 R
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
R: 'async_trait + ActorRef,
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Links this actor with a child, notifying the child actor if the parent dies through Actor::on_link_died, but not visa versa.
sourcefn unlink_child<'life0, 'life1, 'async_trait, R>(
&'life0 self,
child: &'life1 R
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
R: 'async_trait + ActorRef,
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn unlink_child<'life0, 'life1, 'async_trait, R>(
&'life0 self,
child: &'life1 R
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
R: 'async_trait + ActorRef,
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Unlinks the actor with a previously linked actor.
sourcefn link_together<'life0, 'life1, 'async_trait, R>(
&'life0 self,
actor_ref: &'life1 R
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
R: 'async_trait + ActorRef,
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn link_together<'life0, 'life1, 'async_trait, R>(
&'life0 self,
actor_ref: &'life1 R
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
R: 'async_trait + ActorRef,
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Links two actors with one another, notifying eachother if either actor dies through Actor::on_link_died.
This operation is atomic.
sourcefn unlink_together<'life0, 'life1, 'async_trait, R>(
&'life0 self,
actor_ref: &'life1 R
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
R: 'async_trait + ActorRef,
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn unlink_together<'life0, 'life1, 'async_trait, R>(
&'life0 self,
actor_ref: &'life1 R
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
R: 'async_trait + ActorRef,
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Unlinks two previously linked actors.
This operation is atomic.
sourcefn notify_link_died<'life0, 'async_trait>(
&'life0 self,
id: u64,
reason: ActorStopReason
) -> Pin<Box<dyn Future<Output = Result<(), ActorError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn notify_link_died<'life0, 'async_trait>(
&'life0 self,
id: u64,
reason: ActorStopReason
) -> Pin<Box<dyn Future<Output = Result<(), ActorError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Notifies the actor that one of its links died.
This is called automatically when an actor dies.
sourcefn 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_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.
sourcefn stop_immediately(&self)
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.
sourcefn wait_for_stop<'life0, 'async_trait>(
&'life0 self
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
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;