@esfx/async-waitqueue Package
The @esfx/async-waitqueue
package provides the WaitQueue class, an async coordination primitive used to queue and resolve promises.
Installation
npm i @esfx/async-waitqueue
Usage
import { WaitQueue } from "@esfx/async-waitqueue";
async function main() {
const queue = new WaitQueue<number>();
// Create two pending "waiters" in the queue
const p1 = queue.wait();
const p2 = queue.wait();
// Resolve the two pending "waiters" in the queue
queue.resolveOne(1);
queue.resolveOne(Promise.resolve(2));
await p1; // 1
await p2; // 2
}
Classes
WaitQueue
An async coordination primitive that provides a queue of Promises.