Loading topic
Promise.all and the others, this chapter reviews the state model they all depend on.2 min readasync functions, use await, and create a promise with new Promise. It also assumes you know that timers and network calls run in the background while JavaScript continues with other code.2 min readthen and await, and know that a promise is pending, fulfilled, or rejected. Before looking at each combinator one at a time, it helps to see the model that all four share. Once you know that model, each combinator comes down to one rule about whe2 min readasync functions, use await inside try/catch, and destructure arrays. It also builds on the earlier idea that work starts when you create a promise, not when you await it.2 min readasync/await with try/catch, and run independent tasks together with Promise.all. Here we look at what happens when one of those tasks fails.2 min readtry/catch works with async functions, and how Promise.all behaves, including its fail-fast rejection. The examples use top-level await, so run them as an ES module, for example in a .mjs file with Node.js 14.8 or later.2 min readPromise.allSettled waits for every input. It also assumes you are comfortable with array methods such as map and filter, with destructuring, and with async/await. The focus here is what to do with the array that allSettled gives back.2 min readasync/await with try/catch, and that you understand that combinators take an iterable and return one promise.2 min readPromise.race settles with the first input that settles. It also assumes you are comfortable with async/await, try/catch/finally, and setTimeout.2 min readasync/await works, and how Promise.race behaves. Promise.any looks a lot like race, but it treats rejections differently.2 min readPromise.any picks the first fulfilled input, and that you are comfortable with try/catch around await. Here we look at the one case where Promise.any rejects: every input has rejected.2 min readPromise.all, Promise.allSettled, Promise.race, and Promise.any. It also assumes you can use async/await and try/catch. The examples use top-level await, so save them as .mjs files and run them with Node.js 14.8 o2 min readPromise.all, Promise.allSettled, Promise.race, and Promise.any. You should also be comfortable with async/await and try/catch. All four combinators were covered one at a time. This chapter compares them so you can pick one quic2 min readPromise.all, Promise.race, and Promise.any settle, and that you have seen the timeout pattern built with Promise.race. You should also be comfortable with async/await and try/finally.2 min readPromise.all collects results in input order, and that you understand the difference between sequential awaiting and starting every task at once. Both topics were covered earlier in this tutorial.2 min read