Options
All
  • Public
  • Public/Protected
  • All
Menu

Interface Promise<T>

Type parameters

  • T

Hierarchy

  • Promise

Callable

  • Promise<T>(resolver: function): Promise<T>
  • Promise<T>(resolver: function): Promise<T>
  • Type parameters

    • T

    Parameters

    • resolver: function
        • (resolve: function, reject: function, notify: function): void
        • Parameters

          • resolve: function
          • reject: function
              • (reason: any): void
              • Parameters

                • reason: any

                Returns void

          • notify: function
              • (progress: any): void
              • Parameters

                • progress: any

                Returns void

          Returns void

    Returns Promise<T>

  • Type parameters

    • T

    Parameters

    • resolver: function
        • (resolve: function, reject: function, notify: function): void
        • Parameters

          • resolve: function
              • (val: T): void
              • Parameters

                • val: T

                Returns void

          • reject: function
              • (reason: any): void
              • Parameters

                • reason: any

                Returns void

          • notify: function
              • (progress: any): void
              • Parameters

                • progress: any

                Returns void

          Returns void

    Returns Promise<T>

Index

Methods

catch

  • catch<U>(onRejected: function): Promise<U>
  • catch<U>(onRejected: function): Promise<U>
  • A sugar method, equivalent to promise.then(undefined, onRejected).

    Type parameters

    • U

    Parameters

    • onRejected: function
        • (reason: any): U
        • Parameters

          • reason: any

          Returns U

    Returns Promise<U>

  • A sugar method, equivalent to promise.then(undefined, onRejected).

    Type parameters

    • U

    Parameters

    • onRejected: function

    Returns Promise<U>

delay

  • Returns a promise that will have the same result as promise, but will only be fulfilled or rejected after at least ms milliseconds have passed.

    Parameters

    • ms: number

    Returns Promise<T>

delete

  • delete<U>(propertyName: String): Promise<U>
  • Type parameters

    • U

    Parameters

    • propertyName: String

    Returns Promise<U>

done

  • done(onFulfilled?: function, onRejected?: function, onProgress?: function): void
  • Much like then, but with different behavior around unhandled rejection. If there is an unhandled rejection, either because promise is rejected and no onRejected callback was provided, or because onFulfilled or onRejected threw an error or returned a rejected promise, the resulting rejection reason is thrown as an exception in a future turn of the event loop.

    This method should be used to terminate chains of promises that will not be passed elsewhere. Since exceptions thrown in then callbacks are consumed and transformed into rejections, exceptions at the end of the chain are easy to accidentally, silently ignore. By arranging for the exception to be thrown in a future turn of the event loop, so that it won't be caught, it causes an onerror event on the browser window, or an uncaughtException event on Node.js's process object.

    Exceptions thrown by done will have long stack traces, if Q.longStackSupport is set to true. If Q.onerror is set, exceptions will be delivered there instead of thrown in a future turn.

    The Golden Rule of done vs. then usage is: either return your promise to someone else, or if the chain ends with you, call done to terminate it.

    Parameters

    • Optional onFulfilled: function
        • (value: T): any
        • Parameters

          • value: T

          Returns any

    • Optional onRejected: function
        • (reason: any): any
        • Parameters

          • reason: any

          Returns any

    • Optional onProgress: function
        • (progress: any): any
        • Parameters

          • progress: any

          Returns any

    Returns void

fail

  • fail<U>(onRejected: function): Promise<U>
  • fail<U>(onRejected: function): Promise<U>
  • Type parameters

    • U

    Parameters

    • onRejected: function

    Returns Promise<U>

  • Type parameters

    • U

    Parameters

    • onRejected: function
        • (reason: any): U
        • Parameters

          • reason: any

          Returns U

    Returns Promise<U>

fapply

  • fapply<U>(args: any[]): Promise<U>
  • Type parameters

    • U

    Parameters

    • args: any[]

    Returns Promise<U>

fcall

  • fcall<U>(...args: any[]): Promise<U>
  • Type parameters

    • U

    Parameters

    • Rest ...args: any[]

    Returns Promise<U>

fin

  • fin(finallyCallback: function): Promise<T>
  • Like a finally clause, allows you to observe either the fulfillment or rejection of a promise, but to do so without modifying the final value. This is useful for collecting resources regardless of whether a job succeeded, like closing a database connection, shutting a server down, or deleting an unneeded key from an object.

    finally returns a promise, which will become resolved with the same fulfillment value or rejection reason as promise. However, if callback returns a promise, the resolution of the returned promise will be delayed until the promise returned from callback is finished.

    Parameters

    • finallyCallback: function
        • (): any
        • Returns any

    Returns Promise<T>

finally

  • finally(finallyCallback: function): Promise<T>
  • Like a finally clause, allows you to observe either the fulfillment or rejection of a promise, but to do so without modifying the final value. This is useful for collecting resources regardless of whether a job succeeded, like closing a database connection, shutting a server down, or deleting an unneeded key from an object.

    finally returns a promise, which will become resolved with the same fulfillment value or rejection reason as promise. However, if callback returns a promise, the resolution of the returned promise will be delayed until the promise returned from callback is finished.

    Parameters

    • finallyCallback: function
        • (): any
        • Returns any

    Returns Promise<T>

get

  • get<U>(propertyName: String): Promise<U>
  • Returns a promise to get the named property of an object. Essentially equivalent to

    promise.then(function (o) { return o[propertyName]; });

    Type parameters

    • U

    Parameters

    • propertyName: String

    Returns Promise<U>

inspect

  • Returns a "state snapshot" object, which will be in one of three forms:

    • { state: "pending" }
    • { state: "fulfilled", value: }
    • { state: "rejected", reason: }

    Returns PromiseState<T>

invoke

  • invoke<U>(methodName: String, ...args: any[]): Promise<U>
  • Returns a promise for the result of calling the named method of an object with the given variadic arguments. The object itself is this in the function, just like a synchronous method call.

    Type parameters

    • U

    Parameters

    • methodName: String
    • Rest ...args: any[]

    Returns Promise<U>

isFulfilled

  • isFulfilled(): boolean
  • Returns whether a given promise is in the fulfilled state. When the static version is used on non-promises, the result is always true.

    Returns boolean

isPending

  • isPending(): boolean
  • Returns whether a given promise is in the pending state. When the static version is used on non-promises, the result is always false.

    Returns boolean

isRejected

  • isRejected(): boolean
  • Returns whether a given promise is in the rejected state. When the static version is used on non-promises, the result is always false.

    Returns boolean

keys

  • Returns a promise for an array of the property names of an object. Essentially equivalent to

    promise.then(function (o) { return Object.keys(o); });

    Returns Promise<string[]>

nodeify

  • nodeify(callback: function): Promise<T>
  • If callback is a function, assumes it's a Node.js-style callback, and calls it as either callback(rejectionReason) when/if promise becomes rejected, or as callback(null, fulfillmentValue) when/if promise becomes fulfilled. If callback is not a function, simply returns promise.

    Parameters

    • callback: function
        • (reason: any, value: any): void
        • Parameters

          • reason: any
          • value: any

          Returns void

    Returns Promise<T>

post

  • post<U>(methodName: String, args: any[]): Promise<U>
  • Returns a promise for the result of calling the named method of an object with the given array of arguments. The object itself is this in the function, just like a synchronous method call. Essentially equivalent to

    promise.then(function (o) { return o[methodName].apply(o, args); });

    Type parameters

    • U

    Parameters

    • methodName: String
    • args: any[]

    Returns Promise<U>

progress

  • progress(onProgress: function): Promise<T>
  • A sugar method, equivalent to promise.then(undefined, undefined, onProgress).

    Parameters

    • onProgress: function
        • (progress: any): any
        • Parameters

          • progress: any

          Returns any

    Returns Promise<T>

set

  • set<U>(propertyName: String, value: any): Promise<U>
  • Type parameters

    • U

    Parameters

    • propertyName: String
    • value: any

    Returns Promise<U>

spread

  • spread<U>(onFulfilled: Function, onRejected?: Function): Promise<U>
  • Like then, but "spreads" the array into a variadic fulfillment handler. If any of the promises in the array are rejected, instead calls onRejected with the first rejected promise's rejection reason.

    This is especially useful in conjunction with all

    Type parameters

    • U

    Parameters

    • onFulfilled: Function
    • Optional onRejected: Function

    Returns Promise<U>

then

  • then<U>(onFulfill: function, onReject?: function, onProgress?: Function): Promise<U>
  • then<U>(onFulfill: function, onReject?: function, onProgress?: Function): Promise<U>
  • then<U>(onFulfill: function, onReject?: function, onProgress?: Function): Promise<U>
  • then<U>(onFulfill: function, onReject?: function, onProgress?: Function): Promise<U>
  • The then method from the Promises/A+ specification, with an additional progress handler.

    Type parameters

    • U

    Parameters

    • onFulfill: function
    • Optional onReject: function
    • Optional onProgress: Function

    Returns Promise<U>

  • The then method from the Promises/A+ specification, with an additional progress handler.

    Type parameters

    • U

    Parameters

    • onFulfill: function
    • Optional onReject: function
        • (reason: any): U
        • Parameters

          • reason: any

          Returns U

    • Optional onProgress: Function

    Returns Promise<U>

  • The then method from the Promises/A+ specification, with an additional progress handler.

    Type parameters

    • U

    Parameters

    • onFulfill: function
        • (value: T): U
        • Parameters

          • value: T

          Returns U

    • Optional onReject: function
    • Optional onProgress: Function

    Returns Promise<U>

  • The then method from the Promises/A+ specification, with an additional progress handler.

    Type parameters

    • U

    Parameters

    • onFulfill: function
        • (value: T): U
        • Parameters

          • value: T

          Returns U

    • Optional onReject: function
        • (reason: any): U
        • Parameters

          • reason: any

          Returns U

    • Optional onProgress: Function

    Returns Promise<U>

thenReject

  • thenReject(reason: any): Promise<T>
  • A sugar method, equivalent to promise.then(function () { throw reason; }).

    Parameters

    • reason: any

    Returns Promise<T>

thenResolve

  • thenResolve<U>(value: U): Promise<U>
  • A sugar method, equivalent to promise.then(function () { return value; }).

    Type parameters

    • U

    Parameters

    • value: U

    Returns Promise<U>

timeout

  • timeout(ms: number, message?: string): Promise<T>
  • Parameters

    • ms: number
    • Optional message: string

    Returns Promise<T>

valueOf

  • valueOf(): any
  • Returns any