pub struct Runtime { /* private fields */ }
Expand description
An actor runtime.
Actors can be activated by the runtime and execute autonomously until they return. Running
actors can be sent messages using the send
method, which does not wait for a response from the
recipient. If a reply is needed, then call
can be used, which returns a future that will
be ready when the reply has been received.
Implementations§
source§impl Runtime
impl Runtime
pub fn path(&self) -> &Arc<BlockPath>
sourcepub async fn num_running(&self) -> usize
pub async fn num_running(&self) -> usize
Returns the number of actors that are currently executing in this Runtime.
sourcepub async fn send<T: 'static + SendMsg>(
&self,
to: ActorName,
from: ActorName,
msg: T
) -> Result<()>
pub async fn send<T: 'static + SendMsg>( &self, to: ActorName, from: ActorName, msg: T ) -> Result<()>
Sends a message to the actor identified by the given ActorName.
sourcepub async fn call<T: 'static + CallMsg>(
&self,
to: ActorName,
from: ActorName,
msg: T
) -> Result<T::Reply>
pub async fn call<T: 'static + CallMsg>( &self, to: ActorName, from: ActorName, msg: T ) -> Result<T::Reply>
Sends a message to the actor identified by the given ActorName and returns a future which is ready when a reply has been received.
sourcepub async fn resolve<'a>(&'a self, _service: &ServiceName) -> Result<ActorName>
pub async fn resolve<'a>(&'a self, _service: &ServiceName) -> Result<ActorName>
Resolves the given ServiceName to an ActorName which is part of it.
sourcepub async fn activate<Msg, F, Fut>(&'static self, activator: F) -> ActorNamewhere
Msg: 'static + CallMsg,
Fut: 'static + Send + Future<Output = ()>,
F: FnOnce(&'static Runtime, Receiver<Envelope<Msg>>, Uuid) -> Fut,
pub async fn activate<Msg, F, Fut>(&'static self, activator: F) -> ActorNamewhere Msg: 'static + CallMsg, Fut: 'static + Send + Future<Output = ()>, F: FnOnce(&'static Runtime, Receiver<Envelope<Msg>>, Uuid) -> Fut,
Activates a new actor using the given activator function and returns a handle to it.
sourcepub async fn register<Msg, Fut, F, G>(
&self,
_id: ServiceId,
_activator: F,
_deserializer: G
) -> Result<()>where
Msg: 'static + CallMsg,
Fut: 'static + Send + Future<Output = ()>,
F: Fn(Receiver<Envelope<Msg>>, Uuid) -> Fut,
G: 'static + Send + Sync + Fn(&[u8]) -> Result<Msg>,
pub async fn register<Msg, Fut, F, G>( &self, _id: ServiceId, _activator: F, _deserializer: G ) -> Result<()>where Msg: 'static + CallMsg, Fut: 'static + Send + Future<Output = ()>, F: Fn(Receiver<Envelope<Msg>>, Uuid) -> Fut, G: 'static + Send + Sync + Fn(&[u8]) -> Result<Msg>,
Registers an actor as a service with the given ServiceId.
sourcepub async fn take(&self, name: &ActorName) -> Result<ActorHandle>
pub async fn take(&self, name: &ActorName) -> Result<ActorHandle>
Returns the ActorHandle for the actor with the given name.
If there is no such actor in this runtime then a RuntimeError::BadActorName error is returned.
Note that the actor will be aborted when the given handle is dropped (unless it has already returned when the handle is dropped), and no further messages will be delivered to it by this runtime.
sourcepub fn actor_name(&self, act_id: Uuid) -> ActorName
pub fn actor_name(&self, act_id: Uuid) -> ActorName
Returns the name of the actor in this runtime with the given actor ID.