niagara
asynchronous map and filter (while keeping a given concurrency limit)
Installation:
Install from npm:
$ npm install niagara --save
Use case
Throttle HTTP requests down to a level that your server can handle or gracefully digest computation heavy asynchronous operations.
Examples:
;; var maxRunning = 0;var currentlyRunning = 0; const callResource = { currentlyRunning++; maxRunning = Math return ;}; const resourceIds = '1''2''3'/*....*/'456'; ;
;; const callUnreliableResource = { return ;}; const resourceIds = '1''2''3'/*....*/'456'; ;
API:
Niagara(collection, options)
var falls = ;
An instance can be constructed without using the new
keyword. Possible options
are limit
, setting the concurrency limit for all transformations and Promise
for the promise implementation to use. If no Promise implementation is passed the library will look for a globally available or native version.
Niagara.setPromise(promiseImplementation)
You can configure the module with a default value for the used Promise implementation. This will be used when no implementation was passed in the options.
Niagara;var victoriaFalls = ; //uses bluebirdvar iguazuFalls = ; //uses promise.js
#map(transform [, thisArg])
;
#filter(predicate [, thisArg])
;
License
MIT © Frederik Ring