reduce-future
Why?
Reduce boils down a list of values into a single values. With reduce-future, you will able to reduce one list that need execute async functions, joining the results on success callback.
Installation
Via npm:
npm install reduce-future
Features
* Reduce array list of objects, executing async operations
* Monolithic and Parallel methods
* Timeout support.
* Immediate finished when error occur.
* Unified error handling.
* No magic on finished callback, just one done function.
Test on node
$ git clone git@github.com:pflima92/reduce-future.git$ cd reduce-future && npm install
Example
var _rf = ; { // If id generated is GREATER that 5000 call err callback ifid > 5000 ; return; // Execute callback of success ;} //Generate random id'svar ids = ;for var i = 0; i < 10; i++ ids; // Create CompletableFuture instance// When call parallel() indicates that alghoritm is a parallel process// When call reduce() indicates that alghoritm is a monolitich process_rf //Add all ids to be processed next { //Define the each iteration flow //Call external services ; };
API
reduce
Create new CompletabeFuture class with default options.
parallel
Create new CompletabeFuture class with parallel option marked with true.
CompletableFuture
Class (ES6) responsible for manage reduce future features.
.add(Object)
Add element to CompletableFuture, can be called any times that is needed, return your own instance.
.addAll(Array)
Add array and concat at elements of CompletableFuture, can be called any times that is needed, return your own instance.
.next(Function)
Add function that will be called on each iteration of CompletableFuture execution
The callback of next future need be signed like:
{ }
.fail(Function)
Add error callback. Is called when next function call fail() method.
.done(Function)
Function that receive the callback parameter, responsible for join the results of interration
License
MIT