Expand description
Actor abstraction for region-owned, message-driven concurrency.
Actors in Asupersync are region-owned tasks that process messages from a bounded mailbox. They integrate with the runtime’s structured concurrency model:
- Region-owned: Actors are spawned within a region and cannot outlive it.
- Cancel-safe mailbox: Messages use the two-phase reserve/send pattern.
- Lifecycle hooks:
on_startandon_stopfor initialization and cleanup.
§Example
ⓘ
struct Counter {
count: u64,
}
impl Actor for Counter {
type Message = u64;
async fn handle(&mut self, _cx: &Cx, msg: u64) {
self.count += msg;
}
}
// In a scope:
let (handle, stored) = scope.spawn_actor(
&mut state, &cx, Counter { count: 0 }, 32,
)?;
state.store_spawned_task(handle.task_id(), stored);
// Send messages:
handle.send(&cx, 5).await?;
handle.send(&cx, 10).await?;
// Stop the actor:
handle.stop();
let result = (&mut handle).join(&cx).await?;
assert_eq!(result.count, 15);Structs§
- Actor
Context - Actor-specific capability context extending
Cx. - Actor
Handle - Handle to a running actor, used to send messages and manage its lifecycle.
- ActorId
- Unique identifier for an actor.
- Actor
Join Future - Future returned by
ActorHandle::join. - Actor
Ref - A lightweight, clonable reference to an actor’s mailbox.
- Mailbox
Config - Configuration for actor mailbox.
Enums§
- Actor
State - Lifecycle state for an actor.
- Supervised
Outcome - Outcome of a supervised actor run.
- Supervisor
Message - Messages that can be sent to a supervisor about child lifecycle events.
Constants§
- DEFAULT_
MAILBOX_ CAPACITY - The default mailbox capacity for actors.
Traits§
- Actor
- A message-driven actor that processes messages from a bounded mailbox.