import { Letter } from '@actor-system/mail'; import { ActorContext, behavior } from '@actor-system/core'; declare const withStash: (capacity: number, factory: (stashBuffer: StashBuffer) => behavior.Behavior) => behavior.Behavior; interface UnstashOptions { /** * Number of messages to unstash. * @default Number.POSITIVE_INFINITY */ amount?: number; /** * Function to transform messages when unstashing. */ map?: (msg: T) => T; } declare class StashBuffer { #private; readonly capacity: number; static create(capacity: number, context: ActorContext): StashBuffer; private constructor(); get size(): number; /** * Return the first element of the message buffer without removing it. * @returns the first element or throws NoSuchElementError if the buffer is empty * @throws {NoSuchElementError} if the buffer is empty */ get head(): T; /** * Returns an iterable of messages in the buffer in insertion order. * @returns An iterable of messages. */ values(): SetIterator; /** * Removes all messages from the buffer. */ clear(): void; /** * Add one element to the end of the message buffer. * @throws {StashOverflowError} if the buffer is full. */ stash(msg: T): this; /** * Request replay of up to `numberOfMessages` messages using `map`. * * If called while another unstash is in progress, it does not replay * immediately; it just marks that another replay is requested. * * Once the current replay finishes, any pending requests are bundled * and a single replay pass is run again. */ unstash(behavior: behavior.Behavior, options?: UnstashOptions): behavior.Behavior; } declare const $noSuchElementError = "@@with-stash.no-such-element-error"; declare class NoSuchElementError extends Error implements Letter { static readonly label = "@@with-stash.no-such-element-error"; readonly label: typeof $noSuchElementError; constructor(); } declare const $stashOverflowError = "@@with-stash.stash-overflow-error"; declare class StashOverflowError extends Error implements Letter { static readonly label = "@@with-stash.stash-overflow-error"; readonly label: typeof $stashOverflowError; constructor(message: string); } export { NoSuchElementError, StashBuffer, StashOverflowError, withStash }; export type { UnstashOptions };