Resolve array of promises in sequence
29 Nov 2023 · 1 min read
1. Introduction
There are several use cases of resolving promise in Javascript.
- Resolve value once (commonly used)
- Multiple resolve at the same time, order of resolve does not matter (i.e. upload multiple images)
- Multiple resolve one at a time, order of resolve is important (i.e. call an API function or task sequentially after the previous call completed)
2. How it's done
const sequentialFn = async () => {
for (const item of list) {
await task(item);
}
}
It may seem to be the same as other iterable function method but there is a significant difference in behaviour and this will get the job done.
Thanks for reading, cheers!