README
Serial-Promises
a clean way to resolve promises in serie
How does it work ?
You can use SerialPromises.all exactly like you would use Promise.all with the only difference that you must provide functions instead of Promises.
Installation
yarn:
yarn add serial-promises
npm :
npm install serial-promises --save
Example
3 promises resolved in serie vs 3 promises resolved in parallel
import SerialPromises from 'serial-promises';
let foo = function (text) {
return new Promise((resolve) => {
setTimeout(() => {
console.log(text);
resolve(text);
}, 1000);
});
};
/*serie*/
SerialPromises.all([
() => foo('A'),
() => foo('B'),
() => foo('C'),
]).then((results) => {
//["A", "B", "C"]
});
/*parallel (native code)*/
Promise.all([
foo('A'),
foo('B'),
foo('C'),
]).then((results) => {
//["A", "B", "C"]
});