Skip to main content

Module actor

Module actor 

Source
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_start and on_stop for 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§

ActorContext
Actor-specific capability context extending Cx.
ActorHandle
Handle to a running actor, used to send messages and manage its lifecycle.
ActorId
Unique identifier for an actor.
ActorJoinFuture
Future returned by ActorHandle::join.
ActorRef
A lightweight, clonable reference to an actor’s mailbox.
MailboxConfig
Configuration for actor mailbox.

Enums§

ActorState
Lifecycle state for an actor.
SupervisedOutcome
Outcome of a supervised actor run.
SupervisorMessage
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.