promise-queue-easy
v1.0.7
Published
queue promise
Downloads
6
Maintainers
Readme
Promise.queue
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