Demo
Install
$ yarn add ng-promise-queue
Or
$ npm install ng-promise-queue
Add To Your Angular App
Supports usage of modules or require.js. Expects angular to be available globally, so if using a module bundler (webpack) be sure your setup supports this.
const ngPromiseQueue = // Only the modules .name property is exported angular
Or more more traditionally just reference the file from a script tag
<script src="node_modules/ng-promise-queue/dist/ngPromiseQueue.min.js"></script> angular // just reference the module's name as string
Use
ngPromiseQueue exposes a factory that you can inject.
{ promiseQueue}
.run()
is the only method exposed from the promiseQueue factory. It takes a simple configuration object as its only argument
{ // must be an array, can contain whatever data your callback needs to operate on const tasks = 123 // The number of tasks you'd like to run at the same time const maxConcurrent = 2 // will default to 1 if not passed // A callback function that returns a promise and takes a task as an argument const promiseCb = { return } const config = tasks maxConcurrent promiseCb promiseQueue}
promiseQueue.run()
returns a promise, the promise will resolve when all tasks are complete.
{ promiseQueue // Even if the promiseCb is rejected, the outer promiseQueue promise will still continue. // If the promiseCb raises an exception the queue will be rejected and the exception caught here }
Results are returned as an array, and in the order that they resolved or were rejected
{ promiseQueue }
Development
Install dependencies
$ yarn
Run tests
$ yarn test
Build
$ yarn build