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
Actortrait — defines the message handling interfaceActorContext— per-actor context with peer ID, router address, and child actor managementAddr— a clonable, hashable address for sending messages to an actor
§Channel Types
Actors can use either unbounded or bounded channels:
- Unbounded (default) —
ActorContext::start_actorcreates an actor with an unbounded channel. No backpressure; messages are always enqueued. - Bounded —
ActorContext::start_actor_boundedcreates an actor with a bounded channel of the given capacity. When full,Addr::sendreturnsErr(()), 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§
- Actor
Context - 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.