Iterator based utilities for handling sync & async tasks like async execution with a maximum for parallel tasks at the same time.
Don't get fooled by this repository last update, this repository is maintained and we use it daily where I work. It is just that we aren't having any bugs.
This library is based in iterators, that means, it can work over everything that is iterable (arrays, generators, strings, ...). Just use the static method iterate
and select the method. There is two basic patters here: sequential and parallel (witch admits a maximum of concurrency).
Execute the promises one after the other, always waiting to the previous one to finish before executing the next Promise.
var piped = require('iterated-pipes');
piped
.iterate([...])
.sequential(url => request(url))
.then(lastValue => {...});
Iterate all the items and return an array with the results. Is like a Promise.all but accepts a maximum quantity of maximum executions in parallel.
var piped = require('iterated-pipes');
piped
.iterate([...])
.parallel(10, url => request(url)) //Executes a maximum of 10 calls at a time. When one call ends, call the next one
.then(results => {...}); //All the results in the same order
Is important to make a distinction between this method and the ones that use Promise.all internally. This one executes the next call just after one call is finish meanwhile other methods execute X callbacks with Promise.all, waiting until the last one to continue the execution, making these methods less time efficient.