Stashing
Stashing is a mechanism you can enable in your actors, so they can temporarily stash away messages they cannot or should not handle at the moment. Another way to see it is that stashing allows you to keep processing messages you can handle while saving for later messages you can't. Stashing are handled by GoAkt out of the actor instance just like the mailbox, so if the actor dies while processing a message, all messages in the stash are processed. This feature is usually used together with Become/UnBecome, as they fit together very well, but this is not a requirement.
Itβs recommended to avoid stashing too many messages to avoid too much memory usage. If you try to stash more messages than the capacity the actor will panic. To use the stashing feature, call the following methods on the ReceiveContext when handling a message:
Stash()
- adds the current message to the stash buffer.Unstash()
- unstashes the oldest message in the stash and prepends to the stash buffer.UnstashAll()
- unstashes all messages from the stash buffer and prepends in the mailbox. Messages will be processed in the same order they arrived. The stash buffer will be empty after processing all messages, unless an exception is thrown or messages are stashed while unstashing.
Last updated