promise-all-sequential
Extremely lightweight (270 bytes) library for evaluating promises sequentially with zero external dependencies.
const promiseAllSequential = ; const asyncFunc1 = async { ;}; const asyncFunc2 = async { ;}; // Prints "First", then "Second" and returns results;
Essentially, asyncFunc1
is guaranteed to finish before asyncFunc2
gets called. The result will be a promise which resolves with an array of results from the functions.
Installation
This is a Node.js module available through the npm registry.
Before installing, download and install Node.js.
Installation is done using the npm install
command:
$ npm install promise-all-sequential
Examples
Comparison with Promise.all()
that calls functions simultaneously:
// Prints "Second", then "First" - wrong order!Promiseall ;
Comparison with chaining asynchronous functions:
// Using async function chainingconst arr = ;const results = ;console; // Using this library;
Troubleshooting
Please note that you cannot initialize the promise directly, meaning that the following will not work:
const asyncFunc = ...;
This is because a promise starts executing its body as soon as it is created, making it no longer possible to force into sequential order. You must wrap the initialization into a function instead:
const asyncFunc = ...;
If you face any issues, please submit an issue or a pull request.
People
The author of promise-all-sequential is Jonatan Hamberg