Options
All
  • Public
  • Public/Protected
  • All
Menu

Class wraps promise-like objects and adds to them some extra functionality, such as possibility of cancellation, etc.

Type parameters

  • T = unknown

    promise resolved value

Hierarchy

  • default

Implements

  • Promise<T>

Index

Constructors

Properties

[toStringTag]: "Promise"
override
aborted: boolean = false

If true, then the promise was aborted

Handler of the native promise rejection that was raised by a reason of abort

Handler of the native promise rejection

onResolve: ConstrResolveHandler<T>

Handler of the native promise resolving

pendingChildren: number = 0

Number of pending child promises

promise: Promise<T>

Internal native promise instance

state: State = State.pending

Actual promise state

value: unknown

Resolved promise value

Accessors

  • get isPending(): boolean

Methods

  • abort(reason?: unknown): boolean
  • Attaches a common callback for the promise fulfilled and rejected states. The method returns a new promise with the state and value from the current. A value from the passed callback will be ignored unless it equals a rejected promise or exception.

    Parameters

    Returns default<T>

  • all<T>(values: T, parent?: default<unknown>): default<{ [ K in string | number | symbol]: Awaited<T[K]> }>
  • all<T>(values: T, parent?: default<unknown>): default<(T extends Iterable<Value<V>> ? V : unknown)[]>
  • Takes an iterable of promises and returns a single AbortablePromise that resolves to an array of the results of the input promises. This returned promise will resolve when all the input's promises have been resolved or if the input iterable contains no promises. It rejects immediately upon any of the input promises rejecting or non-promises throwing an error and will reject with this first rejection message/error.

    Type parameters

    • T: any[] | []

    Parameters

    • values: T
    • Optional parent: default<unknown>

    Returns default<{ [ K in string | number | symbol]: Awaited<T[K]> }>

  • Type parameters

    • T: Iterable<unknown, T>

    Parameters

    • values: T
    • Optional parent: default<unknown>

    Returns default<(T extends Iterable<Value<V>> ? V : unknown)[]>

  • allSettled<T>(values: T, parent?: default<unknown>): default<{ [ K in string | number | symbol]: PromiseSettledResult<Awaited<T[K]>> }>
  • allSettled<T>(values: T, parent?: default<unknown>): default<(T extends Iterable<Value<V>> ? PromiseSettledResult<V> : PromiseSettledResult<unknown>)[]>
  • Returns a promise that resolves after all the given promises have either been fulfilled or rejected, with an array of objects describing each promise's outcome.

    It is typically used when you have multiple asynchronous tasks that are not dependent on one another to complete successfully, or you'd always like to know the result of each promise.

    In comparison, the AbortablePromise returned by AbortablePromise.all() may be more appropriate if the tasks are dependent on each other / if you'd like to reject upon any of them reject immediately.

    Type parameters

    • T: any[] | []

    Parameters

    • values: T
    • Optional parent: default<unknown>

    Returns default<{ [ K in string | number | symbol]: PromiseSettledResult<Awaited<T[K]>> }>

  • Type parameters

    • T: Iterable<unknown, T>

    Parameters

    • values: T
    • Optional parent: default<unknown>

    Returns default<(T extends Iterable<Value<V>> ? PromiseSettledResult<V> : PromiseSettledResult<unknown>)[]>

  • any<T>(values: T, parent?: default<unknown>): default<T extends Iterable<Value<V>> ? V : unknown>
  • Creates a promise that is resolved when any of the provided promises are resolved or rejected if the provided all promises are rejected

    Type parameters

    • T: Iterable<unknown, T>

    Parameters

    • values: T
    • Optional parent: default<unknown>

    Returns default<T extends Iterable<Value<V>> ? V : unknown>

  • race<T>(values: T, parent?: default<unknown>): default<T extends Iterable<Value<V>> ? V : unknown>
  • Creates an abortable promise that is resolved or rejected when any of the provided promises are resolved or rejected

    Type parameters

    • T: Iterable<unknown, T>

    Parameters

    • values: T
    • Optional parent: default<unknown>

    Returns default<T extends Iterable<Value<V>> ? V : unknown>

  • Returns an AbortablePromise object that is resolved with a given value.

    If the value is a promise, that promise is returned; if the value is a thenable (i.e., has a "then" method), the returned promise will "follow" that thenable, adopting its eventual state; otherwise, the returned promise will be fulfilled with the value.

    This function flattens nested layers of promise-like objects (e.g., a promise that resolves to a promise that resolves to something) into a single layer.

    Type parameters

    • T = unknown

    Parameters

    Returns default<T>

  • Returns a new resolved AbortablePromise object with an undefined value

    Returns default<void>

  • Returns an AbortablePromise object that is resolved with a given value. If the resolved value is a function, it will be invoked. The result of the invoking will be provided as a value of the promise.

    If the value is a promise, that promise is returned; if the value is a thenable (i.e., has a "then" method), the returned promise will "follow" that thenable, adopting its eventual state; otherwise, the returned promise will be fulfilled with the value.

    This function flattens nested layers of promise-like objects (e.g., a promise that resolves to a promise that resolves to something) into a single layer.

    Type parameters

    • T = unknown

    Parameters

    Returns default<T>

  • Returns a new resolved AbortablePromise object with an undefined value

    Returns default<void>

  • wrapReasonToIgnore<T>(reason: T): T
  • The method wraps the specified abort reason to ignore with tied promises, i.e., this reason won't reject all child promises

    Type parameters

    • T: object

    Parameters

    • reason: T

    Returns T