Skip to content

QueueReceiver

Defined in: packages/async/src/synchro/queue-receiver.ts:25

Adapts an @ac-kit/data IQueue’s synchronous, non-blocking dequeue() into an async one that waits for an item instead of returning undefined.

The producer side is the caller’s choice — Queue.enqueue, Queue.waitEnqueue, a LossyQueue’s evicting enqueue, or anything else that ends up calling the same queue’s dequeue() — this class only adapts the consumer side. Call QueueReceiver.notify after every enqueue so a pending QueueReceiver.receive wakes up; a missed notify is not lost (the underlying Signal is level-triggered, not edge-triggered), so calling it unconditionally after every enqueue attempt — successful or not — is always safe.

Assumes a single reader: concurrent receive() calls would race on which one gets which dequeue() result, same as calling dequeue() directly from two tasks would.

T extends DefinedValue

The type of elements in the queue. Anything except undefined.

new QueueReceiver<T>(queue): QueueReceiver<T>

Defined in: packages/async/src/synchro/queue-receiver.ts:28

IQueue<T>

QueueReceiver<T>

notify(): void

Defined in: packages/async/src/synchro/queue-receiver.ts:31

Wakes a pending receive. Call after every enqueue.

void


receive(signal?): Promise<T>

Defined in: packages/async/src/synchro/queue-receiver.ts:40

Waits for and returns the next item, dequeuing it.

AbortSignal | null

An optional abort signal to cancel the wait.

Promise<T>