On this page
  1. Promise & Async
  2. Contents
  3. Promise States & Combinators
  4. async / await & Promise.withResolvers()

Promise & Async

Prev: Collections: Map, Set, WeakMap & WeakSet | Up: builtins | Next: Proxy & Well-Known Symbols
Rel: Event Loop & Async Programming, Fetch & Networking
Ref: MDN Web Docs — Promise
Tags: #public #web #javascript #builtins #async


Contents


Promise States & Combinators

A Promise transitions once from pending to either fulfilled or rejected.

Combinator Resolves When Rejects When
Promise.all(iter) All fulfill First rejects (fail-fast)
Promise.allSettled(iter) All settle (returns status objects) Never
Promise.race(iter) First settles (fulfilled or rejected) First rejects
Promise.any(iter) First fulfills All reject (AggregateError)

async / await & Promise.withResolvers()

async function loadBoth(p1, p2) {
  const [a, b] = await Promise.all([p1, p2]);
  return { a, b };
}

const { promise, resolve } = Promise.withResolvers();
setTimeout(() => resolve("done"), 10);

Linked from

Related notes