Class Promise

Index

Constructor methods

Methods

Functions

Constructor methods

constructor(callback: (resolve: (result: R) => void, reject: (error: any) => void) => void): Promise

If you call resolve in the body of the callback passed to the constructor, your promise is fulfilled with result object passed to resolve. If you call reject your promise is rejected with the object passed to resolve. For consistency and debugging (eg stack traces), obj should be an instanceof Error. Any errors thrown in the constructor callback will be implicitly passed to reject().

Parameters

  • callback: (resolve: (result: R) => void, reject: (error: any) => void) => void

Returns

Promise

constructor(callback: (resolve: (thenable: Thenable<R>) => void, reject: (error: any) => void) => void): Promise

If you call resolve in the body of the callback passed to the constructor, your promise will be fulfilled/rejected with the outcome of thenable passed to resolve. If you call reject your promise is rejected with the object passed to resolve. For consistency and debugging (eg stack traces), obj should be an instanceof Error. Any errors thrown in the constructor callback will be implicitly passed to reject().

Parameters

  • callback: (resolve: (thenable: Thenable<R>) => void, reject: (error: any) => void) => void

Returns

Promise

Methods

public catch(onReject?: (error: any) => Thenable<U>): Promise

Sugar for promise.then(undefined, onRejected)

Parameters

  • onReject?: (error: any) => Thenable<U> optional

    called when/if "promise" rejects

Returns

Promise

public catch(onReject?: (error: any) => U): Promise

Sugar for promise.then(undefined, onRejected)

Parameters

  • onReject?: (error: any) => U optional

    called when/if "promise" rejects

Returns

Promise

public then(onFulfill: (value: R) => Thenable<U>, onReject: (error: any) => Thenable<U>): Promise

onFulFill is called when/if "promise" resolves. onRejected is called when/if "promise" rejects. Both are optional, if either/both are omitted the next onFulfilled/onRejected in the chain is called. Both callbacks have a single parameter , the fulfillment value or rejection reason. "then" returns a new promise equivalent to the value you return from onFulfilled/onRejected after being passed through Promise.resolve. If an error is thrown in the callback, the returned promise rejects with that error.

Parameters

  • onFulfill: (value: R) => Thenable<U>
  • onReject: (error: any) => Thenable<U>

    called when/if "promise" rejects

Returns

Promise

public then(onFulfill: (value: R) => Thenable<U>, onReject?: (error: any) => U): Promise

onFulFill is called when/if "promise" resolves. onRejected is called when/if "promise" rejects. Both are optional, if either/both are omitted the next onFulfilled/onRejected in the chain is called. Both callbacks have a single parameter , the fulfillment value or rejection reason. "then" returns a new promise equivalent to the value you return from onFulfilled/onRejected after being passed through Promise.resolve. If an error is thrown in the callback, the returned promise rejects with that error.

Parameters

  • onFulfill: (value: R) => Thenable<U>
  • onReject?: (error: any) => U optional

    called when/if "promise" rejects

Returns

Promise

public then(onFulfill: (value: R) => U, onReject: (error: any) => Thenable<U>): Promise

onFulFill is called when/if "promise" resolves. onRejected is called when/if "promise" rejects. Both are optional, if either/both are omitted the next onFulfilled/onRejected in the chain is called. Both callbacks have a single parameter , the fulfillment value or rejection reason. "then" returns a new promise equivalent to the value you return from onFulfilled/onRejected after being passed through Promise.resolve. If an error is thrown in the callback, the returned promise rejects with that error.

Parameters

  • onFulfill: (value: R) => U
  • onReject: (error: any) => Thenable<U>

    called when/if "promise" rejects

Returns

Promise

public then(onFulfill?: (value: R) => U, onReject?: (error: any) => U): Promise

onFulFill is called when/if "promise" resolves. onRejected is called when/if "promise" rejects. Both are optional, if either/both are omitted the next onFulfilled/onRejected in the chain is called. Both callbacks have a single parameter , the fulfillment value or rejection reason. "then" returns a new promise equivalent to the value you return from onFulfilled/onRejected after being passed through Promise.resolve. If an error is thrown in the callback, the returned promise rejects with that error.

Parameters

  • onFulfill?: (value: R) => U optional
  • onReject?: (error: any) => U optional

    called when/if "promise" rejects

Returns

Promise

Functions

all(promises: Promise[]): Promise

Make a promise that fulfills when every item in the array fulfills, and rejects if (and when) any item rejects. the array passed to all can be a mixture of promise-like objects and other objects. The fulfillment value is an array (in order) of fulfillment values. The rejection value is the first rejection value.

Parameters

Returns

Promise

cast(promise: Promise): Promise

Returns promise (only if promise.constructor == Promise)

Parameters

Returns

Promise

cast(object?: R): Promise

Make a promise that fulfills to obj.

Parameters

  • object?: R optional

Returns

Promise

race(promises: Promise[]): Promise

Make a Promise that fulfills when any item fulfills, and rejects if any item rejects.

Parameters

Returns

Promise

reject(error?: any): Promise

Make a promise that rejects to obj. For consistency and debugging (eg stack traces), obj should be an instanceof Error

Parameters

  • error?: any optional

Returns

Promise

resolve(thenable: Thenable): Promise

Make a new promise from the thenable. A thenable is promise-like in as far as it has a "then" method. This also creates a new promise if you pass it a genuine JavaScript promise, making it less efficient for casting than Promise.cast.

Parameters

Returns

Promise

resolve(object?: R): Promise

Make a promise that fulfills to obj. Same as Promise.cast(obj) in this situation.

Parameters

  • object?: R optional

Returns

Promise