1.0.8 • Published 7 years ago

piped-promises v1.0.8

Weekly downloads
2
License
MIT
Repository
github
Last release
7 years ago

piped-promises

Not maintained

The project is tested and should work properly, but is not going to be maintained. You can check this one, iterated-pipes

Library with different patters for promises like sequencial & parallel with maximum parallel execution arguments execution.

Build Status Coverage Status

Patters

The library is structured in a sequence of static methods like parallel or secuencial.

The usage is simple, just import the library and use the methods.

Sequential promises

Execute the promises one after the other, always waiting to the previous one to finish before executing the next Promise.

	var piped = require('piped-promises');

	piped.sequential(urls.map(url => (lastCallResult) => request(url)))
	.catch(error => console.log(error))
	.then(callResults => {
		console.log(callResults); //An array with the results of the urls in the same order
	});

sequential required an array of callbacks that will execute the code that return a promise.

In case of error the execution will stop and the error will be available in the sequential catch.

Parallel promises

Execute all promises and return an array with the results of all the promises. Is like a Promise.all but accepts a maximum quantity of maximum executions in parallel.

	var piped = require('piped-promises');

	piped.parallel(urls.map(url => () => request(url)), 10) //Executes a maximum of 10 calls at a time. When one call ends, call the next one
	.catch(error => console.log(error))
	.then(callResults => {
		console.log(callResults); //An array with the results of the urls 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 that methods less time efficient.

TODO

To have an API like:

piped
.iterate(urls)
.parallel(10, url => request(url, options))
.then(results => {...})
.catch(error => {...});
piped
.iterate(urls)
.sequential((url, lastValue) => request(url, options))
.then(results => {...})
.catch(error => {...});
1.0.8

7 years ago

1.0.7

7 years ago

1.0.6

7 years ago

1.0.5

7 years ago

1.0.4

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago