DEV Community

Executing arrays of async/await JavaScript functions in series vs. concurrently

Corey Cleary on March 12, 2019

Originally published at coreycleary.me. This is a cross-post from my content blog. I publish new content every week or two, and you can sign up to ...
Collapse
 
matsaleh profile image
Matthew Walker

Nice article, thanks!

I'd also highly recommend using the caolan/async package. It implements asynchronous functions such as each (iteration), whilst and until (conditional), and waterfall (chaining), among many others. It also has utilities for composing those functions, and many of them have series and parallel variants where appropriate.

It supports async/await and promises, as well as callbacks (when you must). I think it's a great additional tool for async programming with JS, especially with Node.js.

Hope this helps, and cheers!

Collapse
 
dance2die profile image
Sung M. Kim

Thank you Corey for the post~ 🙂

I can think of using the principles in this article and apply on a web page.

Say, if one needs to display a part of webpage as quickly as possible, then we can use the sequential route.

If all contents need to be displayed at once, then concurrently.

Would the application work by chance?

Collapse
 
ccleary00 profile image
Corey Cleary

Hey Sung, yeah I think thats accurate. For fetching things needed for certain parts of the webpage, doing it in series/sequentially will work as long as you load them in the right order (i.e. - the component that needs its data fetched first has its function run before the others)

Collapse
 
dance2die profile image
Sung M. Kim

Thank you for the clarification, Corey~ 🤜