Categories
JavaScript Answers

How to call async/await functions in parallel with Node.js?

Spread the love

Sometimes, we want to call async/await functions in parallel with Node.js.

In this article, we’ll look at how to call async/await functions in parallel with Node.js.

How to call async/await functions in parallel with Node.js?

To call async/await functions in parallel with Node.js, we can call Promise.all.

For instance, we write

await Promise.all([someCall(), anotherCall()]);

to call Promise.all with an array of promises.

We use await to wait for all promises to resolve until we move onto the next line.

And we can store the resolved values with

const [someResult, anotherResult] = await Promise.all([someCall(), anotherCall()]);

Conclusion

To call async/await functions in parallel with Node.js, we can call Promise.all.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *