Chapter 15 of 16All chapters
Chapter 15 of 16
Promises and async
Work that finishes later.
Promises
A promise is a value that arrives later, settling as fulfilled or rejected. then and catch chain onto it, and each link passes its result to the next.
- Promise.all rejects as soon as any one rejects and drops the rest.
- Promise.allSettled waits for every promise and reports each outcome.
async and await
An async function always returns a promise, and await pauses inside it until one settles. Wrap awaits in try and catch, because a rejection there throws like any other error.