Struct coerce::actor::refs::LocalActorRef
source · pub struct LocalActorRef<A: Actor> { /* private fields */ }
Expand description
A reference to a local Actor
instance
Implementations§
source§impl<A: Actor> LocalActorRef<A>
impl<A: Actor> LocalActorRef<A>
pub fn send_blocking<Msg: Message>( &self, msg: Msg ) -> Result<Msg::Result, ActorRefErr>where A: Handler<Msg>,
pub fn stop_blocking(&self) -> Result<(), ActorRefErr>
pub fn exec_blocking<F, R>(&self, f: F) -> Result<R, ActorRefErr>where F: FnMut(&mut A) -> R + 'static + Send + Sync, R: 'static + Send + Sync,
source§impl<A: Actor> LocalActorRef<A>
impl<A: Actor> LocalActorRef<A>
sourcepub fn sender(&self) -> &UnboundedSender<MessageHandler<A>>
pub fn sender(&self) -> &UnboundedSender<MessageHandler<A>>
Get the direct reference to the actor mailbox’s [
[UnboundedSender
][tokio::sync::mpsc::unbounded::UnboundedSender]
source§impl<A: Actor> LocalActorRef<A>
impl<A: Actor> LocalActorRef<A>
sourcepub fn new(
id: ActorId,
sender: UnboundedSender<MessageHandler<A>>,
path: ActorPath
) -> Self
pub fn new( id: ActorId, sender: UnboundedSender<MessageHandler<A>>, path: ActorPath ) -> Self
sourcepub fn actor_path(&self) -> &ActorPath
pub fn actor_path(&self) -> &ActorPath
sourcepub async fn send<Msg: Message>(
&self,
msg: Msg
) -> Result<Msg::Result, ActorRefErr>where
A: Handler<Msg>,
pub async fn send<Msg: Message>( &self, msg: Msg ) -> Result<Msg::Result, ActorRefErr>where A: Handler<Msg>,
Sends a message to the target Actor
and waits for the message to be processed and for
a result to be available.
Example
Send a [Status
][lifecycle::Status] message (a built-in message that every actor can handle), and return the result,
which is an ActorStatus
.
use coerce::actor::{
Actor,
LocalActorRef,
context::ActorStatus,
lifecycle::Status
};
async fn get_status<A: Actor>(actor: &LocalActorRef<A>) -> Option<ActorStatus> {
actor.send(Status).await.ok()
}
sourcepub fn notify<Msg: Message>(&self, msg: Msg) -> Result<(), ActorRefErr>where
A: Handler<Msg>,
pub fn notify<Msg: Message>(&self, msg: Msg) -> Result<(), ActorRefErr>where A: Handler<Msg>,
Sends a message to the target Actor
but doesn’t wait for the message to be processed.
Example
Send a [Stop
][lifecycle::Stop] message, which is a message every actor can handle, but don’t wait for it
to be processed.
use coerce::actor::{
Actor,
LocalActorRef,
lifecycle::Stop,
};
fn stop_actor<A: Actor>(actor: &LocalActorRef<A>) {
let _ = actor.notify(Stop(None));
}
pub async fn exec<F, R>(&self, f: F) -> Result<R, ActorRefErr>where F: FnMut(&mut A) -> R + 'static + Send + Sync, R: 'static + Send + Sync,
pub fn notify_exec<F>(&self, f: F) -> Result<(), ActorRefErr>where F: FnMut(&mut A) + 'static + Send + Sync,
sourcepub async fn status(&self) -> Result<ActorStatus, ActorRefErr>
pub async fn status(&self) -> Result<ActorStatus, ActorRefErr>
Sends a [Status
][lifecycle::Status] message, returning the current [ActorStatus
][context::ActorStatus]
sourcepub async fn stop(&self) -> Result<(), ActorRefErr>
pub async fn stop(&self) -> Result<(), ActorRefErr>
Attempts to stop the target Actor
, waiting for completion
pub fn describe(&self, describe: Describe) -> Result<(), ActorRefErr>
pub fn is_valid(&self) -> bool
sourcepub fn notify_stop(&self) -> Result<(), ActorRefErr>
pub fn notify_stop(&self) -> Result<(), ActorRefErr>
Attempts to stop the target Actor
, without waiting for completion
source§impl<A: Actor> LocalActorRef<A>
impl<A: Actor> LocalActorRef<A>
sourcepub fn scheduled_notify<M: Message>(
&self,
message: M,
delay: Duration
) -> ScheduledNotify<A, M>where
A: Handler<M>,
pub fn scheduled_notify<M: Message>( &self, message: M, delay: Duration ) -> ScheduledNotify<A, M>where A: Handler<M>,
Spawns an asynchronous task that sleeps for the provided duration and finally sends
the provided message to the target Actor
.
Returns a handle to the scheduled notification for cancellation.
Trait Implementations§
source§impl<A: Actor> Clone for LocalActorRef<A>
impl<A: Actor> Clone for LocalActorRef<A>
source§impl<A: Actor> CoreActorRef for LocalActorRef<A>
impl<A: Actor> CoreActorRef for LocalActorRef<A>
fn actor_id(&self) -> &ActorId
fn actor_path(&self) -> &ActorPath
fn actor_type(&self) -> &'static str
fn status<'life0, 'async_trait>( &'life0 self ) -> Pin<Box<dyn Future<Output = Result<ActorStatus, ActorRefErr>> + Send + 'async_trait>>where Self: 'async_trait, 'life0: 'async_trait,
fn stop<'life0, 'async_trait>( &'life0 self ) -> Pin<Box<dyn Future<Output = Result<(), ActorRefErr>> + Send + 'async_trait>>where Self: 'async_trait, 'life0: 'async_trait,
fn describe(&self, describe: Describe) -> Result<(), ActorRefErr>
fn notify_stop(&self) -> Result<(), ActorRefErr>
fn notify_child_terminated(&self, id: ActorId) -> Result<(), ActorRefErr>
fn is_valid(&self) -> bool
fn as_any(&self) -> &dyn Any
source§impl<A: Actor> Debug for LocalActorRef<A>
impl<A: Actor> Debug for LocalActorRef<A>
source§impl<A: Actor> From<LocalActorRef<A>> for ActorRef<A>
impl<A: Actor> From<LocalActorRef<A>> for ActorRef<A>
source§fn from(r: LocalActorRef<A>) -> Self
fn from(r: LocalActorRef<A>) -> Self
source§impl<A: Actor> From<LocalActorRef<A>> for BoxedActorRef
impl<A: Actor> From<LocalActorRef<A>> for BoxedActorRef
source§fn from(r: LocalActorRef<A>) -> Self
fn from(r: LocalActorRef<A>) -> Self
source§impl<A, M: Message> From<LocalActorRef<A>> for Receiver<M>where
A: Handler<M> + Actor,
impl<A, M: Message> From<LocalActorRef<A>> for Receiver<M>where A: Handler<M> + Actor,
source§fn from(actor_ref: LocalActorRef<A>) -> Self
fn from(actor_ref: LocalActorRef<A>) -> Self
source§impl From<LocalActorRef<RemoteClient>> for RemoteClientRef
impl From<LocalActorRef<RemoteClient>> for RemoteClientRef
source§fn from(client: LocalActorRef<RemoteClient>) -> Self
fn from(client: LocalActorRef<RemoteClient>) -> Self
source§impl<A: Actor> Hash for LocalActorRef<A>
impl<A: Actor> Hash for LocalActorRef<A>
source§impl<A, M: Message> MessageReceiver<M> for LocalActorRef<A>where
A: Handler<M> + Actor,
impl<A, M: Message> MessageReceiver<M> for LocalActorRef<A>where A: Handler<M> + Actor,
source§impl<A: Actor> PartialEq for LocalActorRef<A>
impl<A: Actor> PartialEq for LocalActorRef<A>
source§impl Routes for LocalActorRef<ShardingApi>
impl Routes for LocalActorRef<ShardingApi>
source§impl<W: Actor + Clone> WorkerRefExt<W> for LocalActorRef<Worker<W>>
impl<W: Actor + Clone> WorkerRefExt<W> for LocalActorRef<Worker<W>>
source§impl<A: Actor> Deref for LocalActorRef<A>
impl<A: Actor> Deref for LocalActorRef<A>
§type Target = LocalActorRefInner<A>
type Target = LocalActorRefInner<A>
source§fn deref(&self) -> &LocalActorRefInner<A>
fn deref(&self) -> &LocalActorRefInner<A>
impl<A: Actor> Eq for LocalActorRef<A>
Auto Trait Implementations§
impl<A> !RefUnwindSafe for LocalActorRef<A>
impl<A> Send for LocalActorRef<A>
impl<A> Sync for LocalActorRef<A>
impl<A> Unpin for LocalActorRef<A>
impl<A> !UnwindSafe for LocalActorRef<A>
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
§impl<Q, K> Equivalent<K> for Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
impl<Q, K> Equivalent<K> for Qwhere Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
impl<Q, K> Equivalent<K> for Qwhere Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.source§impl<Q, K> Equivalent<K> for Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
impl<Q, K> Equivalent<K> for Qwhere Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,
source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.