Settle Map is a tool that combines the features of Promise.allSettled and Array.map. It simplifies the process of mapping promises, providing results flexibility with hassle free error handling and lets you control how many can run at the same time using concurrency. In other words, it will help you prevent being rate-limited.
Get response value on resolve any item immediately
Catch error immediately on reject any item
Get response immediately on retry any item
Get the final result object
The complete event will not be emitted when omitResult options will be true.
Note
Each event can only trigger one function. If you try to set up multiple listeners for the same event, the most recent one will replace any earlier ones.
To wait and get all result at once you just have to add await keyword like casual async/await approach or invoke the then method.
If you want to wait until all processes are done, you can use the waitUntilFinished method.
you could abort the all remaining processes any time and get the current result using abort method
you could watch the updated status using status method that will return the number of active and pending process
You could specify a retry limit and delay for each promise, in case it fails or is rejected.
A function that settles promises returned by the provided function (fn) for each item in the items array. The promises are settled according to the provided options.
- items (T[]): An array of items to be processed.
- fn ((item: T, index: number) => Promise<R>): A function that takes an item and its index as parameters and returns a Promise.
- options (SettleOptions | number): An object that specifies the concurrency and retry options. If a number is provided, it is treated as the concurrency level. Default is 1
Returns an object with the following methods:
- waitUntilFinished(): A method that returns a promise that resolves when all items have been processed, regardless of whether they succeeded or failed.
- status(): A method that returns the current status of the settling process.
- on(event, listener): A method that allows you to listen for certain events.
- abort(): A method that aborts all remain processes and return the current result.
Note
Since the return value has then method so the settleMap function is awaitable. Followed the Thenable approach. see MDN
A curry function of settleMap that will help you to set default options and use the map function with same option everywhere. even you could modify the options for each individual use.
- GitHub: @fahimfaisaal
- Twitter: @FahimFaisaal
- LinkedIn: in/fahimfaisaal
.png)

![The Complexity of Simplicity [video]](https://www.youtube.com/img/desktop/supported_browsers/edgium.png)