ts-async-iterable-queue
v3.0.1
Published
A queue structure implementing AsyncIterableIterator<T>
Downloads
1,833
Readme
ts-async-iterable-queue
A queue structure implementing AsyncIterableIterator<T>
Usage
import { createAsyncQueue } from 'ts-async-iterable-queue'
const q = createAsyncQueue<number>();
const postToQueue= async () => {
for (let x = 0; x < 100; ++x) {
await delay(1)
q.enqueue(x)
}
q.complete();
}
const receiveFromQueue= async () => {
let i = 0;
for await (const ii of q) {
if(i++ !== ii){
throw Error()
}
}
if(ii !== 100){
throw Error()
}
console.log("queue completed!")
}
postToQueue() // fire-and-forget
receiveFromQueue() // fire-and-forget
acknowledgements
Created using the wonderful https://github.com/alexjoverm/typescript-library-starter.