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()
receiveFromQueue()
acknowledgements
Created using the wonderful https://github.com/alexjoverm/typescript-library-starter.