So far, we've seen how to use promises to perform asynchronous operations in sequence. This is useful when the individual steps are long-running operations. However, this might not always be the more efficient configuration. Quite often, we can perform multiple asynchronous operations at the same time.
In this recipe, we'll see how to use Promise.all
to start multiple asynchronous operations, without waiting for the previous one to complete.
This recipe assumes that you already have a workspace that allows you to create and run ES modules in your browser. If you don't, please see the first two chapters.
- Open your command-line application and navigate to your workspace.
- Create a new folder named
3-06-using-promise-all
. - Copy or create an
index.html
that loads and runs amain
function frommain.js
.
- Create a
main.js
file that creates an object namedrocket
, and callsPromise.all
with an empty array as the first argument:
export...