/** * @license * Copyright 2026 Google LLC * SPDX-License-Identifier: Apache-2.0 */ /** * A generic, single-consumer async queue that implements AsyncIterable, * bridging a *push* producer to a *pull* consumer (`for await (const x of q)`). * * Producers call {@link push} as values are produced and {@link close} (or * {@link fail}) when finished. A single consumer drains the queue. * * Semantics: * - Buffered items are always delivered before an end/error signal. * - {@link close} ends iteration cleanly (`done: true`); idempotent. * - {@link fail} surfaces the error to the consumer *after* any buffered items * have been drained; it is sticky (first failure wins) and also closes the * queue, so a later `close()` can't discard the error. * - {@link push} after close/fail is ignored (the producer has already * signalled completion). */ export declare class AsyncQueue implements AsyncIterable { private queue; private resolvers; private closed; private failure?; /** Whether the queue has been closed or failed. */ get isClosed(): boolean; /** Number of items buffered and not yet consumed. */ get size(): number; /** * Enqueues a value. If a consumer is currently awaiting, it is resolved * immediately; otherwise the value is buffered. No-op once closed/failed. */ push(value: T): void; /** * Signals that production failed. Buffered items are still delivered first; * once the buffer drains, the consumer's next `next()` rejects with `error`. * Sticky (first failure wins) and closes the queue. */ fail(error: unknown): void; /** @deprecated Alias for {@link fail}; kept for existing callers. */ error(err: unknown): void; /** * Signals that no more items will be produced. Any awaiting consumer receives * `{done: true}`. Idempotent. */ close(): void; [Symbol.asyncIterator](): AsyncIterator; }