Specialised runtime for Heph actors.
If this is your introduction to Heph it better to start with the Heph crate first.
The root of the crate has two main types:
- [
Runtime] is Heph's runtime, used to run all actors. - [
RuntimeRef] is a reference to a running runtime, used for example to spawn new actors.
Running Heph's runtime
Building a runtime starts with calling setup, which will create a new
Setup builder type, which allows configuration of the
[Runtime]. The new function can also be used, but is really only meant
for quick prototyping or testing.
Setup has a number of configuration options. An example of one
such option is the number of threads the runtime uses, this can configured
with the num_threads and use_all_cores methods. When using
use_all_cores the CPU affinity can automatically be set using
auto_cpu_affinity.
Once the runtime is fully configured it can be build, which returns the
[Runtime] type.
After the runtime is build it is also possible to start thread-safe actors
using [Spawn] implementation on Runtime or try_spawn. Synchronous
actors can be spawned using spawn_sync_actor. Note however that most
actors should run as thread-local actors however. To spawn a thread-local
actor see the [Spawn] implementation for [RuntimeRef] or
[RuntimeRef::try_spawn_local], which can spawn both thread-safe and
thread-local actors. For documentation on the different kind of actors see
the [actor] module.
To help with initialisation and spawning of thread-local actor it's possible
to run functions on all worker threads using run_on_workers. This will
run the same (cloned) function on all workers threads with access to a
[RuntimeRef].
Finally after configurating the runtime and spawning actors the runtime can
be started, which runs all actors and waits for them to complete.
Examples
This simple example shows how to run a Runtime and add how start a single
actor on each thread. This should print "Hello World" twice (once on each
worker thread started).
use actor;
use NoSupervisor;
use ActorOptions;
use ;
// This setup function will on run on each created thread. In the case of
// this example we create two threads (see `main`).
>
/// Our actor that greets people.
async
For more examples see the examples directory in the source code.
Features
This crate has one optional: test. The test feature will enable the
test module which adds testing facilities.