Skip to main content
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).

Enabling stashing

Pass WithStashing() as a SpawnOption:
Without 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 StashNonReentrant mode, 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.