

Minimum supported Rust version: 1.39 or later.We only want to do one computation in this example, so we // shut down the `System` which will stop any Arbiters within // it (including the System Arbiter), which will in turn stop // any Actor Contexts running within those Arbiters, finally // shutting down all Actors. Spawn the future onto the current Arbiter/event loop WeĬan use Arbiter::spawn to assist with this task.įn handle( & mut self, msg: Value, _ctx: & mut Context) -> Self:: Result ", e) Consider we have two actors, A andī, and we want to run an event on B only once a result from A is completed. Wrapper to resolving async events in order. If you aren't an expert in Rust Futures, Arbiter can be a helpful and simple The method of passing messages isĪgnostic to whether the Actors are running on the same or different Arbiters. Using the normal Addr/ Recipient methods. However, Actors on different Arbiters can still communicate with each other Move between Arbiters: they are tied to the Arbiter they were spawned in. The new thread is available to add new Actors to it, but Actors cannot freely When you create a new Arbiter, this creates a new execution context for Actors. Multiple Arbiters using Arbiter::new, ArbiterBuilder, or Arbiter::start. To use Actix in a concurrent way, you can spin up

You think Arbiter, you can think "single-threaded event loop".Īctix in general does support concurrency, but normal Arbiters (not Spawns a task (via Arbiter::spawn, Context::run_later, or similarĬonstructs), the Arbiter queues the task for execution on that task queue. One Arbiter is in control of one thread with one event pool. For this usecase, read the next section andĬonsider using SyncArbiter. Tasks, it's better to avoid blocking the event loop and instead offload theĬomputation to other threads. Which works well for asynchronous events. While it only uses one thread, it uses the very efficient event loop pattern Running inside of the System Arbiter's thread. When you call start() on your actor it is then In all our previous code examples the function System::new creates an Arbiterįor your actors to run inside. To spawn a new OS thread, run an event loop, spawn tasks asynchronously on thatĮvent loop, and act as helpers for asynchronous tasks.

Where anĪctor contains a Context that defines its Actor specific execution state,Īrbiters host the environment where an actor runs.Īs a result Arbiters perform a number of functions. Arbiters provide an asynchronous execution context for Actors, functions and futures.
