Skip to main content

Module actor

Module actor 

Source
Expand description

Actor framework — a lightweight actor model built on Tokio channels.

This module provides a minimal actor system inspired by Alice Ryhl’s “Actors with Tokio” guide. Actors communicate via typed messages over channels and run on the Tokio async runtime.

§Architecture

  • Actor trait — defines the message handling interface
  • ActorContext — per-actor context with peer ID, router address, and child actor management
  • Addr — a clonable, hashable address for sending messages to an actor

§Channel Types

Actors can use either unbounded or bounded channels:

  • Unbounded (default) — ActorContext::start_actor creates an actor with an unbounded channel. No backpressure; messages are always enqueued.
  • BoundedActorContext::start_actor_bounded creates an actor with a bounded channel of the given capacity. When full, Addr::send returns Err(()), applying backpressure. Used for storage write actors where unbounded queue growth is undesirable.

Both channel types are abstracted behind [AddrSender]/[AddrReceiver] enums, so callers use the same Addr::send API regardless of channel type.

§Message Flow

Sender → Addr.send(msg) → Channel (bounded or unbounded)
                               ↓
                         Actor.handle(msg, ctx)
                               ↓
                         Actor can:
                         - spawn child actors
                         - send to router
                         - spawn child tasks

§Shutdown

Actors are stopped via a stop signal channel. When the context’s stop() method is called, all child tasks are aborted and stop signals are sent to all child actors.

Structs§

ActorContext
Per-actor context providing access to runtime services.
Addr
A clonable, hashable address for sending messages to an actor.

Traits§

Actor
The core actor trait.