iterated-pipes

1.0.7 • Public • Published

Iterated Pipes

Iterator based utilities for handling sync & async tasks like async execution with a maximum for parallel tasks at the same time.

Build Status Coverage Status Code Climate npm version

Index

Methods

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).

sequential

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 => {...});

parallel

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.

Package Sidebar

Install

npm i iterated-pipes

Weekly Downloads

6

Version

1.0.7

License

MIT

Unpacked Size

33.8 kB

Total Files

21

Last publish

Collaborators

  • davidbm