0.1.2 • Published 7 years ago

p-q v0.1.2

Weekly downloads
4
License
ISC
Repository
github
Last release
7 years ago

p-q

Tiny promise fifo queue

Build Status

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);
})