Enabling stashing
PassWithStashing() as a SpawnOption:
WithStashing(), calls to Stash, Unstash, or UnstashAll record ErrStashBufferNotSet.
API
Stashed messages are processed in FIFO order when unstashed.
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.