1.0.7 • Published 5 years ago

promise-queue-easy v1.0.7

Weekly downloads
4
License
MIT
Repository
github
Last release
5 years ago

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