Stashing lets an actor temporarily buffer messages instead of processing them. Use it when the actor cannot handle certain messages in its current state (e.g., waiting for a resource, or during a behavior transition).Documentation Index
Fetch the complete documentation index at: https://docs.goakt.dev/llms.txt
Use this file to discover all available pages before exploring further.
Enabling stashing
PassWithStashing() as a SpawnOption:
WithStashing(), calls to Stash, Unstash, or UnstashAll record ErrStashBufferNotSet.
API
| Method | Purpose |
|---|---|
ctx.Stash() | Buffer the current message. It will not be processed until unstashed. The message is moved to a side buffer; the actor continues with the next message. |
ctx.Unstash() | Dequeue the oldest stashed message and prepend it to the mailbox. Processes one message. |
ctx.UnstashAll() | Move all stashed messages back to the mailbox in arrival order. |
When to use
- Behavior transitions — Stash messages you cannot handle in the current behavior; unstash after switching.
- Conditional processing — Stash messages until a condition is met (e.g., dependency ready, lock acquired).
- Reentrancy — With
StashNonReentrantmode, in-flight Ask requests cause user messages to be stashed automatically until the request completes.
Example
A gate actor that buffers requests until opened:Stash size
pid.StashSize() returns the number of messages currently in the stash. Useful for metrics or backpressure.