p-q
v0.1.2
Published
tiny fifo promise queue
Downloads
2
Readme
p-q
Tiny promise fifo queue
npm i --save p-q
Usage
Pass in a processing function that returns a promise to the constructor.
const PQ = require('p-q');
const q = PQ((msg) => {
return new Promise(function(resolve, reject) {
setTimeout(function () {
resolve(msg);
}, 1000);
});
});
Then add some data to the queue:
q.add({
foo: 'hii',
bar: 'world'
})
Get events back:
q.on('processed', data => {
console.log(`${JSON.stringify(data)} was processed`);
})
q.on('empty', _ => {
console.log('queue is empty');
})
q.on('error', err => {
console.error(err);
})
q.on('add', data => {
console.log('new event added', data);
})