pub struct LocalActorRef<A: Actor> { /* private fields */ }
Expand description

A reference to a local Actor instance

Implementations§

source§

impl<A: Actor> LocalActorRef<A>

source

pub fn send_blocking<Msg: Message>( &self, msg: Msg ) -> Result<Msg::Result, ActorRefErr>where A: Handler<Msg>,

source

pub fn stop_blocking(&self) -> Result<(), ActorRefErr>

source

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>

source

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>

source

pub fn new( id: ActorId, sender: UnboundedSender<MessageHandler<A>>, path: ActorPath ) -> Self

Creates a LocalActorRef instance from an ActorId, UnboundSender<MessageHandler<A>>, a system_id (Uuid) and an ActorPath.

Generally this should not be used directly.

source

pub fn actor_id(&self) -> &ActorId

Returns a reference to the ActorId of the target Actor

source

pub fn actor_path(&self) -> &ActorPath

Returns a reference to the ActorPath of the target Actor

source

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()
}
source

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));
}
source

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,

source

pub fn notify_exec<F>(&self, f: F) -> Result<(), ActorRefErr>where F: FnMut(&mut A) + 'static + Send + Sync,

source

pub async fn status(&self) -> Result<ActorStatus, ActorRefErr>

Sends a [Status][lifecycle::Status] message, returning the current [ActorStatus][context::ActorStatus]

source

pub async fn stop(&self) -> Result<(), ActorRefErr>

Attempts to stop the target Actor, waiting for completion

source

pub fn describe(&self, describe: Describe) -> Result<(), ActorRefErr>

source

pub fn is_valid(&self) -> bool

source

pub fn notify_stop(&self) -> Result<(), ActorRefErr>

Attempts to stop the target Actor, without waiting for completion

source§

impl<A: Actor> LocalActorRef<A>

source

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>

source§

fn clone(&self) -> Self

Returns a copy 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> CoreActorRef for LocalActorRef<A>

source§

fn actor_id(&self) -> &ActorId

source§

fn actor_path(&self) -> &ActorPath

source§

fn actor_type(&self) -> &'static str

source§

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,

source§

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

source§

fn describe(&self, describe: Describe) -> Result<(), ActorRefErr>

source§

fn notify_stop(&self) -> Result<(), ActorRefErr>

source§

fn notify_child_terminated(&self, id: ActorId) -> Result<(), ActorRefErr>

source§

fn is_valid(&self) -> bool

source§

fn as_any(&self) -> &dyn Any

source§

impl<A: Actor> Debug for LocalActorRef<A>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<A: Actor> From<LocalActorRef<A>> for ActorRef<A>

source§

fn from(r: LocalActorRef<A>) -> Self

Converts to this type from the input type.
source§

impl<A: Actor> From<LocalActorRef<A>> for BoxedActorRef

source§

fn from(r: LocalActorRef<A>) -> Self

Converts to this type from the input type.
source§

impl<A, M: Message> From<LocalActorRef<A>> for Receiver<M>where A: Handler<M> + Actor,

source§

fn from(actor_ref: LocalActorRef<A>) -> Self

Converts to this type from the input type.
source§

impl From<LocalActorRef<RemoteClient>> for RemoteClientRef

source§

fn from(client: LocalActorRef<RemoteClient>) -> Self

Converts to this type from the input type.
source§

impl<A: Actor> Hash for LocalActorRef<A>

source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl<A, M: Message> MessageReceiver<M> for LocalActorRef<A>where A: Handler<M> + Actor,

source§

fn actor_id(&self) -> &ActorId

source§

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

source§

fn notify(&self, msg: M) -> Result<(), ActorRefErr>

source§

impl<A: Actor> PartialEq for LocalActorRef<A>

source§

fn eq(&self, other: &Self) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Routes for LocalActorRef<ShardingApi>

source§

fn routes(&self, router: Router) -> Router

source§

impl<W: Actor + Clone> WorkerRefExt<W> for LocalActorRef<Worker<W>>

source§

fn dispatch<'life0, 'async_trait, M>( &'life0 mut self, message: M ) -> Pin<Box<dyn Future<Output = Result<M::Result, ActorRefErr>> + Send + 'async_trait>>where W: Handler<M>, M: 'async_trait + Message, Self: 'async_trait, 'life0: 'async_trait,

source§

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

§

type Target = LocalActorRefInner<A>

The resulting type after dereferencing.
source§

fn deref(&self) -> &LocalActorRefInner<A>

Dereferences the value.
source§

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> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. Read more
§

impl<Q, K> Equivalent<K> for Qwhere Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
§

impl<Q, K> Equivalent<K> for Qwhere Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
source§

impl<Q, K> Equivalent<K> for Qwhere Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
§

impl<Q, K> Equivalent<K> for Qwhere Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> FromRef<T> for Twhere T: Clone,

§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
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 Twhere 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<T, M> MessageReceiverClone<M> for Twhere T: 'static + MessageReceiver<M> + Clone, M: Message,

§

impl<T> Pointable for T

§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for Twhere T: Clone,

§

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 Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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.
§

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

§

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