Resolve array of promises in sequence

29 November 2023
One at a time
react-native javascript

1. Introduction

There are several use cases of resolving promise in Javascript.

  1. Resolve value once (commonly used)
  2. Multiple resolve at the same time, order of resolve does not matter (i.e. upload multiple images)
  3. 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!