Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
Arrow up icon
GO TO TOP
ECMAScript Cookbook

You're reading from   ECMAScript Cookbook Over 70 recipes to help you learn the new ECMAScript (ES6/ES8) features and solve common JavaScript problems

Arrow left icon
Product type Paperback
Published in Mar 2018
Publisher Packt
ISBN-13 9781788628174
Length 348 pages
Edition 1st Edition
Languages
Arrow right icon
Author (1):
Arrow left icon
 Harrison Harrison
Author Profile Icon Harrison
Harrison
Arrow right icon
View More author details
Toc

Table of Contents (20) Chapters Close

Title Page
Copyright and Credits
Dedication
PacktPub.com
Contributors
Preface
1. Building with Modules FREE CHAPTER 2. Staying Compatible with Legacy Browsers 3. Working with Promises 4. Working with async/await and Functions 5. Web Workers, Shared Memory, and Atomics 6. Plain Objects 7. Creating Classes 8. Inheritance and Composition 9. Larger Structures with Design Patterns 10. Working with Arrays 11. Working with Maps and Symbols 12. Working with Sets 1. Other Books You May Enjoy Index

Using Promise.all to collect an array of async results


In the previous recipe, we saw how to trigger multiple asynchronous functions before awaiting their results. We've also seen how well the Promise API and asyc/await operators work together. There are some situations where it is preferable to use the Promise API.

In this recipe, we'll see how to use Promise.all to collect the result of multiple asynchronous operations.

Getting ready

This recipe assumes 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.

How to do it...

  1. Open your command-line application and navigate to your workspace.
  2. Create a new folder named 04-06-Promise-all-collect-concurrently.
  3. Create three functions, checkEngines, checkFlightPlan, and checkNavigationSystem that log a message when they start and return a Promise that resolves to true if a random number is higher than a threshold after some timeout:
function checkEngines() { 
  console...
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime
Visually different images