Class Future<T, E>

Represents a Future, which is a subclass of Promise.

Type Parameters

  • T

    The type of the resolved value.

  • E extends Error = Error

    The type of the rejected error.

Hierarchy

  • Promise<T>
    • Future

Constructors

  • Creates a new Future instance.

    Type Parameters

    • T
    • E extends Error = Error

    Parameters

    • executor: ((resolve, reject) => void)

      A function that is called immediately with the resolve and reject functions.

        • (resolve, reject): void
        • Parameters

          • resolve: ((value) => void)
              • (value): void
              • Parameters

                • value: T

                Returns void

          • reject: ((error) => void)
              • (error): void
              • Parameters

                • error: E

                Returns void

          Returns void

    Returns Future<T, E>

Properties

[toStringTag]: string
state: "Pending" | "Fulfilled" | "Rejected"
[species]: PromiseConstructor

Methods

  • Attaches a callback for only the rejection of the Promise.

    Type Parameters

    • TResult = never

    Parameters

    • Optional onrejected: null | ((reason) => TResult | PromiseLike<TResult>)

      The callback to execute when the Promise is rejected.

    Returns Promise<T | TResult>

    A Promise for the completion of the callback.

  • Attaches a callback that is invoked when the Promise is settled (fulfilled or rejected). The resolved value cannot be modified from the callback.

    Parameters

    • Optional onfinally: null | (() => void)

      The callback to execute when the Promise is settled (fulfilled or rejected).

    Returns Promise<T>

    A Promise for the completion of the callback.

  • Checks if the Future is in the fulfilled state.

    Returns boolean

    True if the Future is fulfilled, false otherwise.

  • Checks if the Future is in the pending state.

    Returns boolean

    True if the Future is pending, false otherwise.

  • Checks if the Future is in the rejected state.

    Returns boolean

    True if the Future is rejected, false otherwise.

  • Asynchronously retrieves the result of the future.

    Returns Promise<Result<T, E>>

    A promise that resolves to a Result object containing either the value or the error.

  • Attaches callbacks for the resolution and/or rejection of the Promise.

    Type Parameters

    • TResult1 = T
    • TResult2 = never

    Parameters

    • Optional onfulfilled: null | ((value) => TResult1 | PromiseLike<TResult1>)

      The callback to execute when the Promise is resolved.

    • Optional onrejected: null | ((reason) => TResult2 | PromiseLike<TResult2>)

      The callback to execute when the Promise is rejected.

    Returns Promise<TResult1 | TResult2>

    A Promise for the completion of which ever callback is executed.

  • Creates a Promise that is resolved with an array of results when all of the provided Promises resolve, or rejected when any Promise is rejected.

    Type Parameters

    • T

    Parameters

    • values: Iterable<T | PromiseLike<T>>

      An iterable of Promises.

    Returns Promise<Awaited<T>[]>

    A new Promise.

  • Creates a Promise that is resolved with an array of results when all of the provided Promises resolve, or rejected when any Promise is rejected.

    Type Parameters

    • T extends readonly unknown[] | []

    Parameters

    • values: T

      An array of Promises.

    Returns Promise<{
        -readonly [P in string | number | symbol]: Awaited<T[P<P>]>
    }>

    A new Promise.

  • Creates a Promise that is resolved with an array of results when all of the provided Promises resolve or reject.

    Type Parameters

    • T extends readonly unknown[] | []

    Parameters

    • values: T

      An array of Promises.

    Returns Promise<{
        -readonly [P in string | number | symbol]: PromiseSettledResult<Awaited<T[P<P>]>>
    }>

    A new Promise.

  • Creates a Promise that is resolved with an array of results when all of the provided Promises resolve or reject.

    Type Parameters

    • T

    Parameters

    • values: Iterable<T | PromiseLike<T>>

      An array of Promises.

    Returns Promise<PromiseSettledResult<Awaited<T>>[]>

    A new Promise.

  • The any function returns a promise that is fulfilled by the first given promise to be fulfilled, or rejected with an AggregateError containing an array of rejection reasons if all of the given promises are rejected. It resolves all elements of the passed iterable to promises as it runs this algorithm.

    Type Parameters

    • T extends readonly unknown[] | []

    Parameters

    • values: T

      An array or iterable of Promises.

    Returns Promise<Awaited<T[number]>>

    A new Promise.

  • The any function returns a promise that is fulfilled by the first given promise to be fulfilled, or rejected with an AggregateError containing an array of rejection reasons if all of the given promises are rejected. It resolves all elements of the passed iterable to promises as it runs this algorithm.

    Type Parameters

    • T

    Parameters

    • values: Iterable<T | PromiseLike<T>>

      An array or iterable of Promises.

    Returns Promise<Awaited<T>>

    A new Promise.

  • Creates a Future that rejects with the given error.

    Type Parameters

    • T
    • E extends Error = Error

    Parameters

    • error: string | E

      The error to reject with.

    Returns Future<T, E>

    A new Future instance.

  • Creates a Future from an existing Promise.

    Type Parameters

    • T
    • E extends Error = Error

    Parameters

    • promise: Promise<T> | PromiseComposer<T>

      The Promise to create the Future from.

    Returns Future<T, E>

    A new Future instance.

  • Creates a Future that resolves with the given value.

    Type Parameters

    • T
    • E extends Error = Error

    Parameters

    • value: T

      The value to resolve with.

    Returns Future<T, E>

    A new Future instance.

  • Creates a Promise that is resolved or rejected when any of the provided Promises are resolved or rejected.

    Type Parameters

    • T

    Parameters

    • values: Iterable<T | PromiseLike<T>>

      An iterable of Promises.

    Returns Promise<Awaited<T>>

    A new Promise.

  • Creates a Promise that is resolved or rejected when any of the provided Promises are resolved or rejected.

    Type Parameters

    • T extends readonly unknown[] | []

    Parameters

    • values: T

      An array of Promises.

    Returns Promise<Awaited<T[number]>>

    A new Promise.

  • Creates a new rejected promise for the provided reason.

    Type Parameters

    • T = never

    Parameters

    • Optional reason: any

      The reason the promise was rejected.

    Returns Promise<T>

    A new rejected Promise.

  • Creates a new resolved promise.

    Returns Promise<void>

    A resolved promise.

  • Creates a new resolved promise for the provided value.

    Type Parameters

    • T

    Parameters

    • value: T

      A promise.

    Returns Promise<Awaited<T>>

    A promise whose internal state matches the provided promise.

  • Creates a new resolved promise for the provided value.

    Type Parameters

    • T

    Parameters

    • value: T | PromiseLike<T>

      A promise.

    Returns Promise<Awaited<T>>

    A promise whose internal state matches the provided promise.