language::actorsActors own state and run one handler at a time, including across suspension.
A call waits for completion. A void handler still returns a completion
outcome; use match, ? or handle to deal with failure.
actor Counter {
var count: i64 = 0;
receive fn increment(n: i64) { count = count + n; }
receive fn total() -> i64 { count }
}
fn main() {
let counter = spawn Counter();
counter.increment(42) handle error {
println(f"increment failed: {error}");
return;
};
match counter.total() {
.Ok(value) => println(value),
.Err(error) => println(f"query failed: {error}"),
}
stop(counter);
stopped(counter);
}
fork counter.total() creates a task; await task joins its result.
mailbox(target, on_full: ...) submits without waiting for completion and
refuses value-returning handlers. policy(target, on_full: .Wait) or the .Reject policy
controls admission for completion calls; a bare handle waits for room.
Current completion errors are ActorError<E>. The decided request-recovery
contract adds an inferred request parameter and Rejected(SendFailure<Req>).
Typed retry() and to(target) recovery is pending; this build's reason-only
rejection does not return a consumed request. Do not treat uncertain completion
as permission to retry.
A fails handler returns Failed(E) to a completion caller. When submitted
through a mailbox view, its error faults the actor with its Display text.
stop(actor) requests a graceful stop; stopped(actor) waits for terminal
cleanup. terminate(actor) requests cancellation. Inside an
actor, self is its handle and self.field accesses state. An actor's
handle has that actor's type T.