Learn about our RFC process, Open RFC meetings & more.Join in the discussion! »

promise-queue-easy

1.0.7 • Public • Published

Promise.queue

NPM Build Status codecov NPM Version Dowload Total visitor Visitors in today

support

  • AMD
  • CommonJS
  • Browser

install

npm i promise-queue-easy
or
yarn add promise-queue-easy

test

npm run test

Example

const QueuePromise = require('promise-queue-easy');
 
let p1 = () => {
  return new Promise((resolve, reject) => {
    setTimeout(() => {
      resolve('p1 success;');
    }, 1000);
  });
}
 
let p2 = () => {
  return new Promise((resolve, reject) => {
    // resolve('success')
    setTimeout(() => {
      reject('p2 error;');
    }, 100)
  });
}
 
let p3 = () =>  new Promise((resolve, reject) => {
  resolve('p3 success;')
});
 
 
 
const qp = new QueuePromise([p1, p2, p3], {
  callback: function() {
    console.log('===all done===');
  },
  errorInterrupt: false
});
 
qp.on('success', (res, index) => {
  // res
});
qp.on('error', (err, index) => {
  //err
})
 
qp.run();

doc

new QueuePromise(queue, options):

 queue : promise queue,
 options: {
  callback: Function //(results) => {}  all done callback,
  errorInterrupt: Boolean // True stops subsequent execution when an error is encountered and vice versa
 }

methods:

  • on(event, handle): each execution call
event: String ('success' or 'error');
hanlde: Function
  • add(fun:Function) add promise in queue

  • pause(): pasue execute

  • resume(): resume queue execute

  • get running : return Boolean

Install

npm i promise-queue-easy

DownloadsWeekly Downloads

12

Version

1.0.7

License

MIT

Unpacked Size

118 kB

Total Files

6

Last publish

Collaborators

  • avatar