Options
All
  • Public
  • Public/Protected
  • All
Menu

Interface ExtendedPromise<T>

A promise extended with all the extra functionality of 'promise-stuff'.

Type parameters

  • T

Hierarchy

  • ExtendedPromise

Index

Properties

__@toStringTag

__@toStringTag: "Promise"

A symbol property specifying that this is a promise.

Methods

and

  • Returns a promise that will await this and all the promises in others to resolve and yield their results in an array. If a promise rejects, the returned promise will rejection with the reason of the first rejection.

    Parameters

    • Rest ...others: PromiseLike<T>[]

      The other promises that must be resolved with this one.

    Returns ExtendedPromise<T[]>

    The return type is meant to be Self<T[]>, where Self is the promise type.

cast

  • For use in TypeScript. Returns this but statically typed as a Promise<S>.

    template

    S

    Type parameters

    • S

    Returns ExtendedPromise<S>

    The return type is meant to be Self<S>, where Self is the promise type.

catch

  • catch<TResult>(onrejected?: function | undefined | null): ExtendedPromise<T | TResult>
  • Attaches a callback for only the rejection of the Promise.

    Type parameters

    • TResult

    Parameters

    • Optional onrejected: function | undefined | null

      The callback to execute when the Promise is rejected.

    Returns ExtendedPromise<T | TResult>

    A Promise for the completion of the callback. The return type is meant to be Self<T | TResult>, where Self is the current promise type.

delay

  • delay(time: number | Date): this
  • Returns a promise that will wait after this has finished, and then finish in the same way (resolving or rejecting).

    Parameters

    • time: number | Date

      If a number, the number of milliseconds to wait. If a date, the date to delay until.

    Returns this

each

  • Returns a promise that will execute the given callback if this resolves, and then resolve with the same result.

    Parameters

    Returns this

fallback

  • fallback(...others: (T | PromiseLike<T> | function)[]): this
  • Returns a promise that will wait on this promise followed by the promises (or other objects; see below) in others, in order. It will move on to the next promise once a previous finishes with a rejection. If all the promises reject, the returned promise will reject with the last rejection.

    Each of the arguments in others can be:

    • A function returning a promise, in which case the function will be called once the previous promise rejects, with the reason for the rejection as an argument.
    • A promise, in which case it will be waited on.
    • A value, in which case the returned promise resolves with that value.

    Parameters

    • Rest ...others: (T | PromiseLike<T> | function)[]

      One or more arguments used as fallbacks for this promise.

    Returns this

invert

  • Returns a promise that finishes when this does, but in the opposite manner. If this resolves, the returned promise rejects with the value. If this rejects, the returned promise will resolve with the rejection reason.

    template

    S

    Type parameters

    • S

    Returns ExtendedPromise<S>

    The return type is meant to be Self<S>, where Self is the promise type.

lastly

  • Returns a promise that will execute a callback whether this resolves or rejects, and then finish the same way. The callback will receive the rejection reason or result as an argument.

    Parameters

    Returns this

race

  • race(...others: Promise<T>[]): this
  • Returns a promise that will race this against the promises in others and finish in the same way as the first promise that finishes. Handles the rejections of all the promises.

    template

    S

    Parameters

    • Rest ...others: Promise<T>[]

      The other promises to race against.

    Returns this

stall

  • stall(deadline: number | Date): this
  • Returns a promise that acts like this, but will finish no earlier than the given time (it will stall if this finishes before this time, without resolving or rejecting).

    Parameters

    • deadline: number | Date

      If a number, the time to wait in milliseconds. If a date, the date to wait for.

    Returns this

test

  • Returns a promise that will return true if this resolves and false if this rejects. The returned promise always resolves. Calling this method handles rejections by this.

    Returns ExtendedPromise<boolean>

    The return type is meant to be Self<boolean>, where Self is the promise type.

then

  • then<TResult1, TResult2>(onfulfilled?: function | undefined | null, onrejected?: function | undefined | null): ExtendedPromise<TResult1 | TResult2>
  • Attaches callbacks for the resolution and/or rejection of the Promise.

    Type parameters

    • TResult1

    • TResult2

    Parameters

    • Optional onfulfilled: function | undefined | null

      The callback to execute when the Promise is resolved.

    • Optional onrejected: function | undefined | null

      The callback to execute when the Promise is rejected.

    Returns ExtendedPromise<TResult1 | TResult2>

    A Promise for the completion of which ever callback is executed. The return type is meant to be Self<TResult1 | TResult>.

timeout

  • timeout(deadline: number | Date, onTimeout?: function): this
  • Returns a promise that waits for this to finish for an amount of time depending on the type of deadline. If this does not finish on time, onTimeout will be called. The returned promise will then behave like the promise returned by onTimeout. If onTimeout is not provided, the returned promise will reject with an Error.

    Note that any code already waiting on this to finish will still be waiting. The timeout only affects the returned promise.

    Parameters

    • deadline: number | Date

      If a number, the time to wait in milliseconds. If a date, the date to wait for.

    • Optional onTimeout: function

      Called to produce an alternative promise once this expires. Can be an async function.

        • (): PromiseLike<T>
        • Returns PromiseLike<T>

    Returns this

Generated using TypeDoc