Loading topic
async functions, use await inside try/catch, and create promises with new Promise. It also assumes you know that timers and network requests finish later, on the event loop, while your code keeps running. The previous chapter's recap of pending, fulfilled, 5 min readthen and catch, writing async functions with await, and handling errors with try/catch. It builds on the previous two chapters. The first covered the three promise states. The second showed that starting several prom5 min readasync functions, use await and try/catch, and create promises with new Promise. It also builds on the earlier idea that a combinator takes an iterable and returns one promise. The examples use top-level await, so run them as ES modules (save them as `.mjs5 min readPromise.all collects results in input order, and that you are comfortable with async/await, try/catch, and timers made with setTimeout. The examples use top-level await, so run them as ES modules: save the file with a .mjs extension and run it with N5 min readPromise.all works and how it rejects on the first failure, both covered in the previous two chapters. It also assumes you are comfortable with async/await and try/catch. The examples use top-level await, so run them as ES modules (save the file with an `4 min readPromise.allSettled never rejects. That is why it is useful, and it also creates a risk. Every failure ends up inside the result array, and if you never look there, you never learn about it. This chapter covers how to read the settled result objects correctly, connect each result to the input that 4 min readawait and try/catch, and understand that a promise settles once, either by fulfilling or rejecting. You should also be comfortable with the shared combinator model from earlier chapters, where an iterable goes in and one pro5 min readasync/await, try/catch/finally, and how setTimeout schedules a callback. It also assumes you have read the previous chapter, which covered how Promise.race settles with the first input to settle. Here that rule becomes a reusable timeout helper. You will a4 min readasync/await, try/catch, and the earlier chapters on Promise.all and Promise.race. Promise.any is the combinator for "I need one good answer, and I don't care which source gives it." You hand it several promises. It fulfills as soon as any one of th5 min readPromise.any waits for the first input that fulfills and ignores rejections along the way. Sometimes no input fulfills. Every mirror is down, every cache misses, or every fallback fails. In that case Promise.any has several rejection reasons and no single one is the correct answer. It rejects wit4 min readPromise.all, Promise.allSettled, Promise.race, and Promise.any behave with ordinary lists of promises. It also assumes you are comfortable with async/await, try/catch, and the idea that promise callbacks run as microtasks. Here we look at the5 min readPromise.all, Promise.allSettled, Promise.race, and Promise.any. You should be comfortable with async functions, await, and try/catch. Here we stop looking at the combinators one at a time and compare them, so you can pick the rig5 min readPromise.all stops at the first rejection. Promise.race stops at the first settlement. Promise.any stops at the first fulfillment. None of them stops the work. The timers keep ticking, the HTTP requests keep downloading, and the5 min readPromise.all and Promise.allSettled. You should be comfortable with async functions, closures, and try/catch. The examples use top-level await, so save them as .mjs files and run them wit5 min read