Skip to content

craigmulligan/p-q

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

p-q

Tiny fifo promise 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);
})