Queue - ueue is silent
Event-driven queue manager.
Features
Install
Install via yarn:
yarn add ueue
Install via npm:
npm i ueue
Docs
Read the docs on GitHub pages.
Example
Import
CommonJS
const { Q, } = require('ueue');
ES6
import { Q, } from 'ueue';
Use
Create queue
const q = new Q();
Enqueue things
Consider following script:
const sleep = function (ms) {
return new Promise(res => {
setTimeout(() => res(), ms);
});
};
q
.add(() => 'Test 1')
.then(console.log);
q
.add(async () => (await sleep(1000), 'Test 2'))
.then(console.log);
q.addBunch(
async () => (await sleep(100), '1'),
async () => (await sleep(100), '2')
).then(console.log);
q.addBunch(
async () => (await sleep(100), '1'),
async () => {
await sleep(100);
throw '2';
},
async () => (await sleep(100), '3')
).catch(console.log);
console.log('Test 0');
And following output:
Test 0
Test 1
Test 2
[ { result: '1' }, { result: '2' } ]
[ { result: '1' }, { error: '2' }, { result: '3' } ]