Options
All
  • Public
  • Public/Protected
  • All
Menu

Module Q

Callable

  • If value is a Q promise, returns the promise. If value is a promise from another library it is coerced into a Q promise (where possible).

    Type parameters

    • T

    Parameters

    Returns Promise<T>

  • If value is not a promise, returns a promise that is fulfilled with value.

    Type parameters

    • T

    Parameters

    • value: T

    Returns Promise<T>

Index

Variables

longStackSupport

longStackSupport: boolean

A settable property that lets you turn on long stack trace support. If turned on, "stack jumps" will be tracked across asynchronous promise operations, so that if an uncaught error is thrown by done or a rejection reason's stack property is inspected in a rejection callback, a long stack trace is produced.

onerror

onerror: function

A settable property that will intercept any uncaught errors that would otherwise be thrown in the next tick of the event loop, usually as a result of done. Can be useful for getting the full stack trace of an error in browsers, which is not usually possible with window.onerror.

Type declaration

    • (reason: any): void
    • Parameters

      • reason: any

      Returns void

Functions

all

  • Returns a promise that is fulfilled with an array containing the fulfillment value of each promise, or is rejected with the same rejection reason as the first promise to be rejected.

    Type parameters

    • T

    Parameters

    Returns Promise<T[]>

  • Returns a promise that is fulfilled with an array containing the fulfillment value of each promise, or is rejected with the same rejection reason as the first promise to be rejected.

    Type parameters

    • T

    Parameters

    • promises: any[]

    Returns Promise<T[]>

allResolved

  • Type parameters

    • T

    Parameters

    Returns Promise<Promise<T>[]>

  • Type parameters

    • T

    Parameters

    • promises: any[]

    Returns Promise<Promise<T>[]>

allSettled

  • Returns a promise that is fulfilled with an array of promise state snapshots, but only after all the original promises have settled, i.e. become either fulfilled or rejected.

    Type parameters

    • T

    Parameters

    Returns Promise<PromiseState<T>[]>

  • Returns a promise that is fulfilled with an array of promise state snapshots, but only after all the original promises have settled, i.e. become either fulfilled or rejected.

    Type parameters

    • T

    Parameters

    • promises: any[]

    Returns Promise<PromiseState<T>[]>

async

  • async<T>(generatorFunction: any): function
  • This is an experimental tool for converting a generator function into a deferred function. This has the potential of reducing nested callbacks in engines that support yield.

    Type parameters

    • T

    Parameters

    • generatorFunction: any

    Returns function

      • Parameters

        • Rest ...args: any[]

        Returns Promise<T>

defer

  • Returns a "deferred" object with a: promise property resolve(value) method reject(reason) method notify(value) method makeNodeResolver() method

    Type parameters

    • T

    Returns Deferred<T>

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.

    Type parameters

    • T

    Parameters

    Returns Promise<T>

  • 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.

    Type parameters

    • T

    Parameters

    • value: T
    • ms: number

    Returns Promise<T>

  • Returns a promise that will be fulfilled with undefined after at least ms milliseconds have passed.

    Parameters

    • ms: number

    Returns Promise<void>

denodeify

  • denodeify<T>(nodeFunction: Function, ...args: any[]): function
  • Type parameters

    • T

    Parameters

    • nodeFunction: Function
    • Rest ...args: any[]

    Returns function

      • Parameters

        • Rest ...args: any[]

        Returns Promise<T>

fbind

  • fbind<T>(method: function, ...args: any[]): function
  • fbind<T>(method: function, ...args: any[]): function
  • Type parameters

    • T

    Parameters

    • method: function
        • Parameters

          • Rest ...args: any[]

          Returns IPromise<T>

    • Rest ...args: any[]

    Returns function

      • Parameters

        • Rest ...args: any[]

        Returns Promise<T>

  • Type parameters

    • T

    Parameters

    • method: function
        • (...args: any[]): T
        • Parameters

          • Rest ...args: any[]

          Returns T

    • Rest ...args: any[]

    Returns function

      • Parameters

        • Rest ...args: any[]

        Returns Promise<T>

fcall

  • fcall<T>(method: function, ...args: any[]): Promise<T>
  • Type parameters

    • T

    Parameters

    • method: function
        • (...args: any[]): T
        • Parameters

          • Rest ...args: any[]

          Returns T

    • Rest ...args: any[]

    Returns Promise<T>

invoke

  • invoke<T>(obj: any, functionName: string, ...args: any[]): Promise<T>
  • Type parameters

    • T

    Parameters

    • obj: any
    • functionName: string
    • Rest ...args: any[]

    Returns Promise<T>

isFulfilled

  • isFulfilled(promise: Promise<any>): 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.

    Parameters

    Returns boolean

isPending

  • isPending(promise: Promise<any>): boolean
  • isPending(object: any): 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.

    Parameters

    Returns 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.

    Parameters

    • object: any

    Returns boolean

isPromise

  • isPromise(object: any): boolean
  • Returns whether the given value is a Q promise.

    Parameters

    • object: any

    Returns boolean

isPromiseAlike

  • isPromiseAlike(object: any): boolean
  • Returns whether the given value is a promise (i.e. it's an object with a then function).

    Parameters

    • object: any

    Returns boolean

isRejected

  • isRejected(promise: Promise<any>): 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.

    Parameters

    Returns boolean

mcall

  • mcall<T>(obj: any, functionName: string, ...args: any[]): Promise<T>
  • Type parameters

    • T

    Parameters

    • obj: any
    • functionName: string
    • Rest ...args: any[]

    Returns Promise<T>

nbind

  • nbind<T>(nodeFunction: Function, thisArg: any, ...args: any[]): function
  • Type parameters

    • T

    Parameters

    • nodeFunction: Function
    • thisArg: any
    • Rest ...args: any[]

    Returns function

      • Parameters

        • Rest ...args: any[]

        Returns Promise<T>

nextTick

  • nextTick(callback: Function): void
  • Parameters

    • callback: Function

    Returns void

nfapply

  • nfapply<T>(nodeFunction: Function, args: any[]): Promise<T>
  • Type parameters

    • T

    Parameters

    • nodeFunction: Function
    • args: any[]

    Returns Promise<T>

nfbind

  • nfbind<T>(nodeFunction: Function, ...args: any[]): function
  • Type parameters

    • T

    Parameters

    • nodeFunction: Function
    • Rest ...args: any[]

    Returns function

      • Parameters

        • Rest ...args: any[]

        Returns Promise<T>

nfcall

  • nfcall<T>(nodeFunction: Function, ...args: any[]): Promise<T>
  • Type parameters

    • T

    Parameters

    • nodeFunction: Function
    • Rest ...args: any[]

    Returns Promise<T>

ninvoke

  • ninvoke<T>(nodeModule: any, functionName: string, ...args: any[]): Promise<T>
  • Type parameters

    • T

    Parameters

    • nodeModule: any
    • functionName: string
    • Rest ...args: any[]

    Returns Promise<T>

nmcall

  • nmcall<T>(nodeModule: any, functionName: string, ...args: any[]): Promise<T>
  • Type parameters

    • T

    Parameters

    • nodeModule: any
    • functionName: string
    • Rest ...args: any[]

    Returns Promise<T>

npost

  • npost<T>(nodeModule: any, functionName: string, args: any[]): Promise<T>
  • Type parameters

    • T

    Parameters

    • nodeModule: any
    • functionName: string
    • args: any[]

    Returns Promise<T>

nsend

  • nsend<T>(nodeModule: any, functionName: string, ...args: any[]): Promise<T>
  • Type parameters

    • T

    Parameters

    • nodeModule: any
    • functionName: string
    • Rest ...args: any[]

    Returns Promise<T>

promised

  • promised<T>(callback: function): function
  • Creates a new version of func that accepts any combination of promise and non-promise values, converting them to their fulfillment values before calling the original func. The returned version also always returns a promise: if func does a return or throw, then Q.promised(func) will return fulfilled or rejected promise, respectively.

    This can be useful for creating functions that accept either promises or non-promise values, and for ensuring that the function always returns a promise even in the face of unintentional thrown exceptions.

    Type parameters

    • T

    Parameters

    • callback: function
        • (...args: any[]): T
        • Parameters

          • Rest ...args: any[]

          Returns T

    Returns function

      • Parameters

        • Rest ...args: any[]

        Returns Promise<T>

reject

  • reject<T>(reason?: any): Promise<T>
  • Returns a promise that is rejected with reason.

    Type parameters

    • T

    Parameters

    • Optional reason: any

    Returns Promise<T>

resolve

  • Calling resolve with a pending promise causes promise to wait on the passed promise, becoming fulfilled with its fulfillment value or rejected with its rejection reason (or staying pending forever, if the passed promise does). Calling resolve with a rejected promise causes promise to be rejected with the passed promise's rejection reason. Calling resolve with a fulfilled promise causes promise to be fulfilled with the passed promise's fulfillment value. Calling resolve with a non-promise value causes promise to be fulfilled with that value.

    Type parameters

    • T

    Parameters

    Returns Promise<T>

  • Calling resolve with a pending promise causes promise to wait on the passed promise, becoming fulfilled with its fulfillment value or rejected with its rejection reason (or staying pending forever, if the passed promise does). Calling resolve with a rejected promise causes promise to be rejected with the passed promise's rejection reason. Calling resolve with a fulfilled promise causes promise to be fulfilled with the passed promise's fulfillment value. Calling resolve with a non-promise value causes promise to be fulfilled with that value.

    Type parameters

    • T

    Parameters

    • object: T

    Returns Promise<T>

send

  • send<T>(obj: any, functionName: string, ...args: any[]): Promise<T>
  • Type parameters

    • T

    Parameters

    • obj: any
    • functionName: string
    • Rest ...args: any[]

    Returns Promise<T>

spread

  • spread<U>(promises: any[], onFulfilled: function, onRejected?: function): Promise<U>
  • spread<U>(promises: any[], onFulfilled: function, onRejected?: function): Promise<U>
  • spread<U>(promises: any[], onFulfilled: function, onRejected?: function): Promise<U>
  • spread<U>(promises: any[], onFulfilled: function, onRejected?: function): Promise<U>
  • spread<T, U>(promises: IPromise<T>[], onFulfilled: function, onRejected?: function): Promise<U>
  • spread<T, U>(promises: IPromise<T>[], onFulfilled: function, onRejected?: function): Promise<U>
  • spread<T, U>(promises: IPromise<T>[], onFulfilled: function, onRejected?: function): Promise<U>
  • spread<T, U>(promises: IPromise<T>[], 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

    • promises: any[]
    • onFulfilled: function
        • Parameters

          • Rest ...args: any[]

          Returns IPromise<U>

    • Optional onRejected: function

    Returns 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

    • promises: any[]
    • onFulfilled: function
        • Parameters

          • Rest ...args: any[]

          Returns IPromise<U>

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

          • reason: any

          Returns U

    Returns 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

    • promises: any[]
    • onFulfilled: function
        • (...args: any[]): U
        • Parameters

          • Rest ...args: any[]

          Returns U

    • Optional onRejected: function

    Returns 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

    • promises: any[]
    • onFulfilled: function
        • (...args: any[]): U
        • Parameters

          • Rest ...args: any[]

          Returns U

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

          • reason: any

          Returns U

    Returns 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

    • T

    • U

    Parameters

    • promises: IPromise<T>[]
    • onFulfilled: function
    • Optional onRejected: function

    Returns 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

    • T

    • U

    Parameters

    • promises: IPromise<T>[]
    • onFulfilled: function
    • Optional onRejected: function
        • (reason: any): U
        • Parameters

          • reason: any

          Returns U

    Returns 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

    • T

    • U

    Parameters

    • promises: IPromise<T>[]
    • onFulfilled: function
        • (...args: T[]): U
        • Parameters

          • Rest ...args: T[]

          Returns U

    • Optional onRejected: function

    Returns 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

    • T

    • U

    Parameters

    • promises: IPromise<T>[]
    • onFulfilled: function
        • (...args: T[]): U
        • Parameters

          • Rest ...args: T[]

          Returns U

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

          • reason: any

          Returns U

    Returns Promise<U>

timeout

  • timeout<T>(promise: Promise<T>, ms: number, message?: string): Promise<T>
  • Returns a promise that will have the same result as promise, except that if promise is not fulfilled or rejected before ms milliseconds, the returned promise will be rejected with an Error with the given message. If message is not supplied, the message will be "Timed out after " + ms + " ms".

    Type parameters

    • T

    Parameters

    • promise: Promise<T>
    • ms: number
    • Optional message: string

    Returns Promise<T>

when

  • when(): Promise<void>
  • when<T>(value: IPromise<T>): Promise<T>
  • when<T>(value: T): Promise<T>
  • when<T, U>(value: T, onFulfilled: function): Promise<U>
  • when<T, U>(value: T, onFulfilled: function): Promise<U>
  • when<T, U>(value: IPromise<T>, onFulfilled: function, onRejected?: function, onProgress?: function): Promise<U>
  • when<T, U>(value: IPromise<T>, onFulfilled: function, onRejected?: function, onProgress?: function): Promise<U>
  • when<T, U>(value: IPromise<T>, onFulfilled: function, onRejected?: function, onProgress?: function): Promise<U>
  • when<T, U>(value: IPromise<T>, onFulfilled: function, onRejected?: function, onProgress?: function): Promise<U>
  • Returns Promise<void>

  • Type parameters

    • T

    Parameters

    Returns Promise<T>

  • Type parameters

    • T

    Parameters

    • value: T

    Returns Promise<T>

  • Type parameters

    • T

    • U

    Parameters

    • value: T
    • onFulfilled: function

    Returns Promise<U>

  • Type parameters

    • T

    • U

    Parameters

    • value: T
    • onFulfilled: function
        • (val: T): U
        • Parameters

          • val: T

          Returns U

    Returns Promise<U>

  • Type parameters

    • T

    • U

    Parameters

    • value: IPromise<T>
    • onFulfilled: function
    • Optional onRejected: function
    • Optional onProgress: function
        • (progress: any): any
        • Parameters

          • progress: any

          Returns any

    Returns Promise<U>

  • Type parameters

    • T

    • U

    Parameters

    • value: IPromise<T>
    • onFulfilled: function
    • Optional onRejected: function
        • (reason: any): U
        • Parameters

          • reason: any

          Returns U

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

          • progress: any

          Returns any

    Returns Promise<U>

  • Type parameters

    • T

    • U

    Parameters

    • value: IPromise<T>
    • onFulfilled: function
        • (val: T): U
        • Parameters

          • val: T

          Returns U

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

          • progress: any

          Returns any

    Returns Promise<U>

  • Type parameters

    • T

    • U

    Parameters

    • value: IPromise<T>
    • onFulfilled: function
        • (val: T): U
        • Parameters

          • val: T

          Returns U

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

          • reason: any

          Returns U

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

          • progress: any

          Returns any

    Returns Promise<U>