pub struct Runtime { /* private fields */ }Expand description
The runtime that runs all actors.
The runtime will start workers threads that will run all actors, these threads will run until all actors have returned. See the crate documentation for more information.
Implementations
sourceimpl Runtime
impl Runtime
sourcepub const fn setup() -> Setup
pub const fn setup() -> Setup
Setup a new Runtime.
See Setup for the available configuration options.
sourcepub fn try_spawn<S, NA>(
&mut self,
supervisor: S,
new_actor: NA,
arg: NA::Argument,
options: ActorOptions
) -> Result<ActorRef<NA::Message>, NA::Error>where
S: Supervisor<NA> + Send + Sync + 'static,
NA: NewActor<RuntimeAccess = ThreadSafe> + Sync + Send + 'static,
NA::Actor: Send + Sync + 'static,
NA::Message: Send,
pub fn try_spawn<S, NA>(
&mut self,
supervisor: S,
new_actor: NA,
arg: NA::Argument,
options: ActorOptions
) -> Result<ActorRef<NA::Message>, NA::Error>where
S: Supervisor<NA> + Send + Sync + 'static,
NA: NewActor<RuntimeAccess = ThreadSafe> + Sync + Send + 'static,
NA::Actor: Send + Sync + 'static,
NA::Message: Send,
Attempt to spawn a new thread-safe actor.
See the Spawn trait for more information.
sourcepub fn spawn<S, NA>(
&mut self,
supervisor: S,
new_actor: NA,
arg: NA::Argument,
options: ActorOptions
) -> ActorRef<NA::Message>where
S: Supervisor<NA> + Send + Sync + 'static,
NA: NewActor<Error = !, RuntimeAccess = ThreadSafe> + Sync + Send + 'static,
NA::Actor: Send + Sync + 'static,
NA::Message: Send,
pub fn spawn<S, NA>(
&mut self,
supervisor: S,
new_actor: NA,
arg: NA::Argument,
options: ActorOptions
) -> ActorRef<NA::Message>where
S: Supervisor<NA> + Send + Sync + 'static,
NA: NewActor<Error = !, RuntimeAccess = ThreadSafe> + Sync + Send + 'static,
NA::Actor: Send + Sync + 'static,
NA::Message: Send,
Spawn a new thread-safe actor.
See the Spawn trait for more information.
sourcepub fn spawn_sync_actor<S, A>(
&mut self,
supervisor: S,
actor: A,
arg: A::Argument,
options: SyncActorOptions
) -> Result<ActorRef<A::Message>, Error>where
S: SyncSupervisor<A> + Send + 'static,
A: SyncActor<RuntimeAccess = Sync> + Send + 'static,
A::Message: Send + 'static,
A::Argument: Send + 'static,
pub fn spawn_sync_actor<S, A>(
&mut self,
supervisor: S,
actor: A,
arg: A::Argument,
options: SyncActorOptions
) -> Result<ActorRef<A::Message>, Error>where
S: SyncSupervisor<A> + Send + 'static,
A: SyncActor<RuntimeAccess = Sync> + Send + 'static,
A::Message: Send + 'static,
A::Argument: Send + 'static,
Spawn an synchronous actor that runs on its own thread.
For more information and examples of synchronous actors see the
actor module.
sourcepub fn spawn_future<Fut>(&mut self, future: Fut, options: FutureOptions)where
Fut: Future<Output = ()> + Send + Sync + 'static,
pub fn spawn_future<Fut>(&mut self, future: Fut, options: FutureOptions)where
Fut: Future<Output = ()> + Send + Sync + 'static,
Spawn a thread-safe Future.
See RuntimeRef::spawn_future for more documentation.
sourcepub fn run_on_workers<F, E>(&mut self, f: F) -> Result<(), Error>where
F: FnOnce(RuntimeRef) -> Result<(), E> + Send + Clone + 'static,
E: ToString,
pub fn run_on_workers<F, E>(&mut self, f: F) -> Result<(), Error>where
F: FnOnce(RuntimeRef) -> Result<(), E> + Send + Clone + 'static,
E: ToString,
Run the function f on all worker threads.
This can be used to spawn thread-local actors, e.g. TcpServer, or to
initialise thread-local data on each worker thread ensuring that it’s
properly initialised without impacting the performance of the first
request(s).
sourcepub fn receive_signals(&mut self, actor_ref: ActorRef<Signal>)
pub fn receive_signals(&mut self, actor_ref: ActorRef<Signal>)
Receive process signals as messages.
This adds the actor_ref to the list of actor references that will
receive a process signal.
sourcepub fn start(self) -> Result<(), Error>
pub fn start(self) -> Result<(), Error>
Run the runtime.
This will wait until all spawned workers have finished, which happens
when all actors have finished. In addition to waiting for all worker
threads it will also watch for all process signals in Signal and
relay them to actors that want to handle them, see the Signal type
for more information.