2.0.0 • Published 6 years ago
async-concurrency v2.0.0
async-concurrency
Instalation
npm install --save async-concurrency
Classes and functions
- sleep
- Queue
Usage
import {Queue, sleep} from 'async-concurrency';
const q = new Queue<string>();
async function producer() {
await sleep(1000);
q.push('hello(1)');
await sleep(2000);
q.push('hello(2)');
await sleep(3000);
q.push('bye');
await sleep(1000);
q.close();
}
async function consumer() {
while (true) {
const message = await q.shift();
console.log(message);
}
}
consumer().catch(e => console.log(e));
consumer().catch(e => console.log(e));
producer().catch(e => console.log(e));