jsguides

Reference

Async APIs

Promise-based APIs and async patterns.

  1. fetch()

    The Fetch API provides a JavaScript interface for making HTTP requests across the network, returning Promises that resolve to Response objects.

  2. Promise

    The Promise object represents async results, available now, later, or never. Covers creation, chaining, and all six static combinator methods.

  3. Promise.all()

    Promise.all() waits for every promise in an iterable to resolve, returning results in input order. Fails fast on first rejection — use when all must succeed.

  4. Promise.allSettled()

    Promise.allSettled() waits for all promises to settle, returning results for fulfilled and rejected outcomes without short-circuiting on the first failure.

  5. Promise.any()

    Promise.any() takes an iterable of promises and resolves with the first success, or rejects with an AggregateError if all input promises reject.

  6. Promise.prototype.catch()

    Promise.prototype.catch() attaches a rejection handler to a Promise and returns a new Promise, letting you recover from errors or re-throw them in a chain.

  7. Promise.prototype.finally()

    Promise.prototype.finally() runs a callback when a Promise settles. Ideal for cleanup: hiding spinners, closing connections, resetting flags.

  8. Promise.prototype.then()

    Promise.prototype.then() attaches fulfillment and rejection handlers to a Promise, returning a new Promise for chaining async operations.

  9. Promise.race()

    Promise.race() returns a promise that settles as soon as any one promise in the iterable settles, adopting that promise's outcome as its own.

  10. Promise.reject()

    Promise.reject() creates a rejected Promise with a given reason, useful for testing error handlers and conditionally returning failed promises in async code.

  11. Promise.resolve()

    Promise.resolve() turns any value into a resolved Promise, handling plain values, thenables, and Promise pass-through to normalise mixed sync/async code paths.

  12. Promise.try()

    Promise.try() wraps a sync or async callback in a Promise, converting synchronous throws into rejections without deferring the call to a microtask.

  13. Promise.withResolvers()

    Promise.withResolvers() returns a new pending promise with its resolve and reject functions in one call, replacing the hoist-from-executor pattern.