Package Exports
- async-promise-queue
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (async-promise-queue) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
async-promise-queue
A wrapper around the async
module, that provides an improved promise queue.
Some highlights:
- promiseified method (all wired up)
- in a failure scenario, it will wait for pending work before rejecting. This prevents the run-away work problem.
Usage
npm install async-promise-queue
or
yarn add async-promise-queue
Example
'use strict';
const queue = require('async-promise-queue');
// the example worker
const worker = queue.async.asyncify(function(work) {
console.log('work', work.file);
return new Promise(resolve => {
if (work.file === '/path-2') { throw new Error('/path-2'); }
if (work.file === '/path-3') { throw new Error('/path-3'); }
setTimeout(resolve, work.duration);
});
});
// the work
const work = [
{ file:'/path-1', duration: 1000 },
{ file:'/path-2', duration: 50 },
{ file:'/path-3', duration: 100 },
{ file:'/path-4', duration: 50 },
];
// calling our queue helper
queue(worker, work, 3)
.catch(reason => console.error(reason))
.then(value => console.log('complete!!', value))