Member-only story

The Power and Limitations of JavaScript Promise.all

The power of parallel when writing asynchronous JavaScript — and the traps to look out for!

Bret Cameron
Better Programming
4 min readJun 3, 2021
Locks on a bridge
Photo by Alberto Barrera on Unsplash.

In many web development projects, important functionality depends on asynchronous code — whether that’s making HTTPS requests to an API, querying and updating a database, or managing time-sensitive tasks like reading large files.

But are you making sure that your asynchronous code is optimised to run as efficiently as possible?

When I was newer to asynchronous JavaScript, I would often await every promise without realising that I was creating unnecessary bottlenecks in my code. Once I understood some of the benefits of Promise.all, I went through a stage of using it too much. In specific scenarios, my code became inconsistent because I was trying to do things in parallel that affected one another, and the task that happened first was whichever one was fastest!

In this article, we’ll look into the power of parallel while also being mindful of the dangers of using Promise.all too liberally.

How Promise.all Works

We’ll start with a basic example. First, we’ll create an array of numbers from 1 to 100 :

const nums = new…

Create an account to read the full story.

The author made this story available to Medium members only.
If you’re new to Medium, create a new account to read this story on us.

Or, continue in mobile web

Already have an account? Sign in

Bret Cameron
Bret Cameron

Written by Bret Cameron

Writer and developer based in London. On Medium, I mainly write about JavaScript, web development and Rust 💻

No responses yet

Write a response