pub struct ActorHandle<M> { /* private fields */ }Expand description
Handle into an actor which can be used to send messages.
Implementations§
Source§impl<M> ActorHandle<M>
impl<M> ActorHandle<M>
Sourcepub fn new_closed() -> Self
pub fn new_closed() -> Self
Create a closed (disconnected) handle useful for tests.
Source§impl<M> ActorHandle<M>where
M: Send + 'static,
impl<M> ActorHandle<M>where
M: Send + 'static,
Get actor tags.
Sourcepub fn is_running(&self) -> bool
pub fn is_running(&self) -> bool
Check if actor is running.
Running means not initializing, stopping or stopped.
Sourcepub fn is_closed(&self) -> bool
pub fn is_closed(&self) -> bool
Check if actor is closed.
Closed means not initializing or running.
Sourcepub async fn initialized(&self) -> Result<(), ActorError>
pub async fn initialized(&self) -> Result<(), ActorError>
Wait for startup to be complete.
Sourcepub async fn closed(&self) -> Result<(), ActorError>
pub async fn closed(&self) -> Result<(), ActorError>
Wait for actor shutdown.
Sourcepub fn dispatch(&self, message: impl Into<M>) -> Result<(), ActorError>
pub fn dispatch(&self, message: impl Into<M>) -> Result<(), ActorError>
Dispatch message. Will only fail when the actor already has been stopped.
Sourcepub async fn request<T>(
&self,
message: impl FnOnce(Response<T>) -> M,
) -> Result<T, ActorError>
pub async fn request<T>( &self, message: impl FnOnce(Response<T>) -> M, ) -> Result<T, ActorError>
Request with response.
Sourcepub async fn try_request<T, E>(
&self,
message: impl FnOnce(Response<Result<T, E>>) -> M,
) -> Result<T, ActorError>
pub async fn try_request<T, E>( &self, message: impl FnOnce(Response<Result<T, E>>) -> M, ) -> Result<T, ActorError>
Request with response result. If an error is returned in the result it will be wrapped in ´ActorError::Actor`.
Sourcepub fn stream<T>(
&self,
message: impl FnOnce(ResponseStream<T>) -> M,
) -> impl Stream<Item = Result<T, ActorError>>
pub fn stream<T>( &self, message: impl FnOnce(ResponseStream<T>) -> M, ) -> impl Stream<Item = Result<T, ActorError>>
Request with streaming response.
§Errors
The stream only fails if the stream request could not be sent to the actor because it’s not running.
In this case ActorError::InvalidState is returned and the stream ends after it.
Sourcepub fn stream_graceful<T>(
&self,
message: impl FnOnce(ResponseStream<T>) -> M,
) -> impl Stream<Item = T>
pub fn stream_graceful<T>( &self, message: impl FnOnce(ResponseStream<T>) -> M, ) -> impl Stream<Item = T>
Request with streaming response. Gracefully ends the stream when the actor is not running.
Sourcepub fn stream_backpressure<T: Debug>(
&self,
buffer: usize,
message: impl FnOnce(ResponseBackPressureStream<T>) -> M,
) -> impl Stream<Item = Result<T, ActorError>>
pub fn stream_backpressure<T: Debug>( &self, buffer: usize, message: impl FnOnce(ResponseBackPressureStream<T>) -> M, ) -> impl Stream<Item = Result<T, ActorError>>
Request with streaming response with back-pressure.
Trait Implementations§
Source§impl<M> Clone for ActorHandle<M>
impl<M> Clone for ActorHandle<M>
Auto Trait Implementations§
impl<M> Freeze for ActorHandle<M>
impl<M> RefUnwindSafe for ActorHandle<M>
impl<M> Send for ActorHandle<M>where
M: Send,
impl<M> Sync for ActorHandle<M>where
M: Send,
impl<M> Unpin for ActorHandle<M>
impl<M> UnsafeUnpin for ActorHandle<M>
impl<M> UnwindSafe for ActorHandle<M>
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more