Class Promise

Index

Interfaces

Constructor methods

Methods

Interfaces

CancellationError: CancellationError

public message: string

public name: string

Inspection: Inspection

public error(): any

Get the rejection reason for the underlying promise. Throws if the promise wasn't rejected at the creation time of this inspection object.

throws TypeError

Returns

any

public isFulfilled(): boolean

See if the underlying promise was fulfilled at the creation time of this inspection object.

Returns

boolean

public isPending(): boolean

See if the underlying promise was defer at the creation time of this inspection object.

Returns

boolean

public isRejected(): boolean

See if the underlying promise was rejected at the creation time of this inspection object.

Returns

boolean

public value(): R in Promise.Inspection<R>

Get the fulfillment value of the underlying promise. Throws if the promise wasn't fulfilled at the creation time of this inspection object.

throws TypeError

Returns

R in Promise.Inspection<R>

RangeError: RangeError

public message: string

public name: string

RejectionError: RejectionError

public message: string

public name: string

Resolver: Resolver

public callback: (err: any, value: R, ...values: R[]) => void

Gives you a callback representation of the PromiseResolver. Note that this is not a method but a property. The callback accepts error object in first argument and success values on the 2nd parameter and the rest, I.E. node js conventions.

If the the callback is called with multiple success values, the resolver fullfills its promise with an array of the values.

public promise: Promise

Returns a reference to the controlled promise that can be passed to clients.

public progress(value: any)

Progress the underlying promise with value as the progression value.

Parameters

  • value: any

public reject(reason: any)

Reject the underlying promise with reason as the rejection reason.

Parameters

  • reason: any

public resolve(value: R in Promise.Resolver<R>)

Resolve the underlying promise with value as the resolution value. If value is a thenable or a promise, the underlying promise will assume its state.

Parameters

  • value: R in Promise.Resolver<R>

public resolve()

Thenable: Thenable

public then(onFulfilled: (value: R) => Promise.Thenable<U>, onRejected: (error: any) => Promise.Thenable<U>): Thenable

Parameters

  • onFulfilled: (value: R) => Promise.Thenable<U>
  • onRejected: (error: any) => Promise.Thenable<U>

Returns

Thenable

public then(onFulfilled: (value: R) => Promise.Thenable<U>, onRejected?: (error: any) => U): Thenable

Parameters

  • onFulfilled: (value: R) => Promise.Thenable<U>
  • onRejected?: (error: any) => U optional

Returns

Thenable

public then(onFulfilled: (value: R) => U, onRejected: (error: any) => Promise.Thenable<U>): Thenable

Parameters

  • onFulfilled: (value: R) => U
  • onRejected: (error: any) => Promise.Thenable<U>

Returns

Thenable

public then(onFulfilled?: (value: R) => U, onRejected?: (error: any) => U): Thenable

Parameters

  • onFulfilled?: (value: R) => U optional
  • onRejected?: (error: any) => U optional

Returns

Thenable

TimeoutError: TimeoutError

public message: string

public name: string

TypeError: TypeError

public message: string

public name: string

Constructor methods

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

Create a new promise. The passed in function will receive functions resolve and reject as its arguments which can be called to seal the fate of the created promise.

Parameters

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

Returns

Promise

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

Parameters

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

Returns

Promise

Methods

public all(): Promise

Same as calling Promise.all(thisPromise). With the exception that if this promise is bound to a value, the returned promise is bound to that value too.

Returns

Promise

public static all(values: Thenable): Promise

Given an array, or a promise of an array, which contains promises (or a mix of promises and values) return a promise that is fulfilled when all the items in the array are fulfilled. The promise's fulfillment value is an array with fulfillment values at respective positions to the original array. If any promise in the array rejects, the returned promise is rejected with the rejection reason.

Parameters

Returns

Promise

public static all(values: Thenable): Promise

Parameters

Returns

Promise

public static all(values: Thenable[]): Promise

Parameters

Returns

Promise

public static all(values: Array<R>): Promise

Parameters

  • values: Array<R>

Returns

Promise

public any(): Promise

Same as calling Promise.any(thisPromise). With the exception that if this promise is bound to a value, the returned promise is bound to that value too.

Returns

Promise

public static any(values: Thenable): Promise

Like Promise.some(), with 1 as count. However, if the promise fulfills, the fulfillment value is not an array of 1 but the value directly.

Parameters

Returns

Promise

public static any(values: Thenable): Promise

Parameters

Returns

Promise

public static any(values: Thenable[]): Promise

Parameters

Returns

Promise

public static any(values: Array<R>): Promise

Parameters

  • values: Array<R>

Returns

Promise

public static attempt(fn: () => Promise.Thenable<R>, args?: Array<any>, ctx?: any): Promise

Parameters

  • fn: () => Promise.Thenable<R>
  • args?: Array<any> optional
  • ctx?: any optional

Returns

Promise

public static attempt(fn: () => R, args?: Array<any>, ctx?: any): Promise

Parameters

  • fn: () => R
  • args?: Array<any> optional
  • ctx?: any optional

Returns

Promise

public bind(thisArg: any): Promise

Create a promise that follows this promise, but is bound to the given thisArg value. A bound promise will call its handlers with the bound value set to this. Additionally promises derived from a bound promise will also be bound promises with the same thisArg binding as the original promise.

Parameters

  • thisArg: any

Returns

Promise

public static bind(thisArg: any): Promise

Sugar for Promise.resolve(undefined).bind(thisArg);. See .bind().

Parameters

  • thisArg: any

Returns

Promise

public call(propertyName: string, args?: Array<any>): Promise

This is a convenience method for doing:

promise.then(function(obj){ return obj[propertyName].call(obj, arg...); });

Parameters

  • propertyName: string
  • args?: Array<any> optional

Returns

Promise

public cancel(): Promise

Cancel this promise. The cancellation will propagate to farthest cancellable ancestor promise which is still pending.

That ancestor will then be rejected with a CancellationError (get a reference from Promise.CancellationError) object as the rejection reason.

In a promise rejection handler you may check for a cancellation by seeing if the reason object has .name === "Cancel".

Promises are by default not cancellable. Use .cancellable() to mark a promise as cancellable.

Returns

Promise

public cancellable(): Promise

Marks this promise as cancellable. Promises by default are not cancellable after v0.11 and must be marked as such for .cancel() to have any effect. Marking a promise as cancellable is infectious and you don't need to remark any descendant promise.

Returns

Promise

public static cast(value: Thenable): Promise

Cast the given value to a trusted promise. If value is already a trusted Promise, it is returned as is. If value is not a thenable, a fulfilled is: Promise returned with value as its fulfillment value. If value is a thenable (Promise-like object, like those returned by jQuery's $.ajax), returns a trusted that: Promise assimilates the state of the thenable.

Parameters

Returns

Promise

public static cast(value: R): Promise

Parameters

  • value: R

Returns

Promise

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

This is a catch-all exception handler, shortcut for calling .then(null, handler) on this promise. Any exception happening in a .then-chain will propagate to nearest .catch handler.

Alias .caught(); for compatibility with earlier ECMAScript version.

Parameters

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

Returns

Promise

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

Parameters

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

Returns

Promise

public catch(predicate: (error: any) => boolean, onReject: (error: any) => Promise.Thenable<U>): Promise

This extends .catch to work more like catch-clauses in languages like Java or C#. Instead of manually checking instanceof or .name === "SomeError", you may specify a number of error constructors which are eligible for this catch handler. The catch handler that is first met that has eligible constructors specified, is the one that will be called.

This method also supports predicate-based filters. If you pass a predicate function instead of an error constructor, the predicate will receive the error as an argument. The return result of the predicate will be used determine whether the error handler should be called.

Alias .caught(); for compatibility with earlier ECMAScript version.

Parameters

  • predicate: (error: any) => boolean
  • onReject: (error: any) => Promise.Thenable<U>

Returns

Promise

public catch(predicate: (error: any) => boolean, onReject: (error: any) => U): Promise

Parameters

  • predicate: (error: any) => boolean
  • onReject: (error: any) => U

Returns

Promise

public catch(ErrorClass: Function, onReject: (error: any) => Promise.Thenable<U>): Promise

Parameters

  • ErrorClass: Function
  • onReject: (error: any) => Promise.Thenable<U>

Returns

Promise

public catch(ErrorClass: Function, onReject: (error: any) => U): Promise

Parameters

  • ErrorClass: Function
  • onReject: (error: any) => U

Returns

Promise

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

Parameters

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

Returns

Promise

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

Parameters

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

Returns

Promise

public caught(predicate: (error: any) => boolean, onReject: (error: any) => Promise.Thenable<U>): Promise

Parameters

  • predicate: (error: any) => boolean
  • onReject: (error: any) => Promise.Thenable<U>

Returns

Promise

public caught(predicate: (error: any) => boolean, onReject: (error: any) => U): Promise

Parameters

  • predicate: (error: any) => boolean
  • onReject: (error: any) => U

Returns

Promise

public caught(ErrorClass: Function, onReject: (error: any) => Promise.Thenable<U>): Promise

Parameters

  • ErrorClass: Function
  • onReject: (error: any) => Promise.Thenable<U>

Returns

Promise

public caught(ErrorClass: Function, onReject: (error: any) => U): Promise

Parameters

  • ErrorClass: Function
  • onReject: (error: any) => U

Returns

Promise

public static coroutine(generatorFunction: Function): Function

Returns a function that can use yield to run asynchronous code synchronously. This feature requires the support of generators which are drafted in the next version of the language. Node version greater than 0.11.2 is required and needs to be executed with the --harmony-generators (or --harmony) command-line switch.

Parameters

  • generatorFunction: Function

Returns

Function

public static defer(): Resolver

Create a promise with undecided fate and return a PromiseResolver to control it. See resolution?: Promise(#promise-resolution).

Returns

Resolver

public delay(ms: number): Promise

Same as calling Promise.delay(this, ms). With the exception that if this promise is bound to a value, the returned promise is bound to that value too.

Parameters

  • ms: number

Returns

Promise

public static delay(value: Thenable, ms: number): Promise

Returns a promise that will be fulfilled with value (or undefined) after given ms milliseconds. If value is a promise, the delay will start counting down when it is fulfilled and the returned promise will be fulfilled with the fulfillment value of the value promise.

Parameters

Returns

Promise

public static delay(value: R, ms: number): Promise

Parameters

  • value: R
  • ms: number

Returns

Promise

public static delay(ms: number): Promise

Parameters

  • ms: number

Returns

Promise

public done(onFulfilled: (value: R) => Promise.Thenable<U>, onRejected: (error: any) => Promise.Thenable<U>, onProgress?: (note: any) => any): Promise

Like .then(), but any unhandled rejection that ends up here will be thrown as an error.

Parameters

  • onFulfilled: (value: R) => Promise.Thenable<U>
  • onRejected: (error: any) => Promise.Thenable<U>
  • onProgress?: (note: any) => any optional

Returns

Promise

public done(onFulfilled: (value: R) => Promise.Thenable<U>, onRejected?: (error: any) => U, onProgress?: (note: any) => any): Promise

Parameters

  • onFulfilled: (value: R) => Promise.Thenable<U>
  • onRejected?: (error: any) => U optional
  • onProgress?: (note: any) => any optional

Returns

Promise

public done(onFulfilled: (value: R) => U, onRejected: (error: any) => Promise.Thenable<U>, onProgress?: (note: any) => any): Promise

Parameters

  • onFulfilled: (value: R) => U
  • onRejected: (error: any) => Promise.Thenable<U>
  • onProgress?: (note: any) => any optional

Returns

Promise

public done(onFulfilled?: (value: R) => U, onRejected?: (error: any) => U, onProgress?: (note: any) => any): Promise

Parameters

  • onFulfilled?: (value: R) => U optional
  • onRejected?: (error: any) => U optional
  • onProgress?: (note: any) => any optional

Returns

Promise

public error(onReject: (reason: any) => Promise.Thenable<U>): Promise

Like .catch but instead of catching all types of exceptions, it only catches those that don't originate from thrown errors but rather from explicit rejections.

Parameters

  • onReject: (reason: any) => Promise.Thenable<U>

Returns

Promise

public error(onReject: (reason: any) => U): Promise

Parameters

  • onReject: (reason: any) => U

Returns

Promise

public static filter(values: Thenable, filterer: (item: R, index: number, arrayLength: number) => Promise.Thenable<boolean>): Promise

Filter an array, or a promise of an array, which contains a promises (or a mix of promises and values) with the given filterer function with the signature (item, index, arrayLength) where item is the resolved value of a respective promise in the input array. If any promise in the input array is rejected the returned promise is rejected as well.

The return values from the filtered functions are coerced to booleans, with the exception of promises and thenables which are awaited for their eventual result.

*The original array is not modified.

Parameters

  • values: Thenable
  • filterer: (item: R, index: number, arrayLength: number) => Promise.Thenable<boolean>

Returns

Promise

public static filter(values: Thenable, filterer: (item: R, index: number, arrayLength: number) => boolean): Promise

Parameters

  • values: Thenable
  • filterer: (item: R, index: number, arrayLength: number) => boolean

Returns

Promise

public static filter(values: Thenable, filterer: (item: R, index: number, arrayLength: number) => Promise.Thenable<boolean>): Promise

Parameters

  • values: Thenable
  • filterer: (item: R, index: number, arrayLength: number) => Promise.Thenable<boolean>

Returns

Promise

public static filter(values: Thenable, filterer: (item: R, index: number, arrayLength: number) => boolean): Promise

Parameters

  • values: Thenable
  • filterer: (item: R, index: number, arrayLength: number) => boolean

Returns

Promise

public static filter(values: Thenable[], filterer: (item: R, index: number, arrayLength: number) => Promise.Thenable<boolean>): Promise

Parameters

  • values: Thenable[]
  • filterer: (item: R, index: number, arrayLength: number) => Promise.Thenable<boolean>

Returns

Promise

public static filter(values: Thenable[], filterer: (item: R, index: number, arrayLength: number) => boolean): Promise

Parameters

  • values: Thenable[]
  • filterer: (item: R, index: number, arrayLength: number) => boolean

Returns

Promise

public static filter(values: Array<R>, filterer: (item: R, index: number, arrayLength: number) => Promise.Thenable<boolean>): Promise

Parameters

  • values: Array<R>
  • filterer: (item: R, index: number, arrayLength: number) => Promise.Thenable<boolean>

Returns

Promise

public static filter(values: Array<R>, filterer: (item: R, index: number, arrayLength: number) => boolean): Promise

Parameters

  • values: Array<R>
  • filterer: (item: R, index: number, arrayLength: number) => boolean

Returns

Promise

public filter(filterer: (item: U, index: number, arrayLength: number) => Promise.Thenable<boolean>): Promise

Same as calling Promise.filter(thisPromise, filterer). With the exception that if this promise is bound to a value, the returned promise is bound to that value too.

Parameters

  • filterer: (item: U, index: number, arrayLength: number) => Promise.Thenable<boolean>

Returns

Promise

public filter(filterer: (item: U, index: number, arrayLength: number) => boolean): Promise

Parameters

  • filterer: (item: U, index: number, arrayLength: number) => boolean

Returns

Promise

public finally(handler: (value: R) => Promise.Thenable<R>): Promise

Pass a handler that will be called regardless of this promise's fate. Returns a new promise chained from this promise. There are special semantics for .finally() in that the final value cannot be modified from the handler.

Alias .lastly(); for compatibility with earlier ECMAScript version.

Parameters

  • handler: (value: R) => Promise.Thenable<R>

Returns

Promise

public finally(handler: (value: R) => R): Promise

Parameters

  • handler: (value: R) => R

Returns

Promise

public finally(handler: (value: R) => void): Promise

Parameters

  • handler: (value: R) => void

Returns

Promise

public fork(onFulfilled: (value: R) => Promise.Thenable<U>, onRejected: (error: any) => Promise.Thenable<U>, onProgress?: (note: any) => any): Promise

Like .then(), but cancellation of the the returned promise or any of its descendant will not propagate cancellation to this promise or this promise's ancestors.

Parameters

  • onFulfilled: (value: R) => Promise.Thenable<U>
  • onRejected: (error: any) => Promise.Thenable<U>
  • onProgress?: (note: any) => any optional

Returns

Promise

public fork(onFulfilled: (value: R) => Promise.Thenable<U>, onRejected?: (error: any) => U, onProgress?: (note: any) => any): Promise

Parameters

  • onFulfilled: (value: R) => Promise.Thenable<U>
  • onRejected?: (error: any) => U optional
  • onProgress?: (note: any) => any optional

Returns

Promise

public fork(onFulfilled: (value: R) => U, onRejected: (error: any) => Promise.Thenable<U>, onProgress?: (note: any) => any): Promise

Parameters

  • onFulfilled: (value: R) => U
  • onRejected: (error: any) => Promise.Thenable<U>
  • onProgress?: (note: any) => any optional

Returns

Promise

public fork(onFulfilled?: (value: R) => U, onRejected?: (error: any) => U, onProgress?: (note: any) => any): Promise

Parameters

  • onFulfilled?: (value: R) => U optional
  • onRejected?: (error: any) => U optional
  • onProgress?: (note: any) => any optional

Returns

Promise

public inspect(): Inspection

Synchronously inspect the state of this promise. The PromiseInspection will represent the state of the promise as snapshotted at the time of calling .inspect().

Returns

Inspection

public static is(value: any): boolean

See if value is a trusted Promise.

Parameters

  • value: any

Returns

boolean

public isCancellable(): boolean

See if this promise can be cancelled.

Returns

boolean

public isFulfilled(): boolean

See if this promise has been fulfilled.

Returns

boolean

public isPending(): boolean

See if this promise is still defer.

Returns

boolean

public isRejected(): boolean

See if this promise has been rejected.

Returns

boolean

public isResolved(): boolean

See if this promise is resolved -> either fulfilled or rejected.

Returns

boolean

public static join(values?: Thenable[]): Promise

Like Promise.all() but instead of having to pass an array, the array is generated from the passed variadic arguments.

Parameters

Returns

Promise

public static join(values?: Array<R>): Promise

Parameters

  • values?: Array<R> optional

Returns

Promise

public lastly(handler: (value: R) => Promise.Thenable<R>): Promise

Parameters

  • handler: (value: R) => Promise.Thenable<R>

Returns

Promise

public lastly(handler: (value: R) => R): Promise

Parameters

  • handler: (value: R) => R

Returns

Promise

public lastly(handler: (value: R) => void): Promise

Parameters

  • handler: (value: R) => void

Returns

Promise

public static longStackTraces()

Call this right after the library is loaded to enabled long stack traces. Long stack traces cannot be disabled after being enabled, and cannot be enabled after promises have alread been created. Long stack traces imply a substantial performance penalty, around 4-5x for throughput and 0.5x for latency.

public static map(values: Thenable, mapper: (item: R, index: number, arrayLength: number) => Promise.Thenable<U>): Promise

Map an array, or a promise of an array, which contains a promises (or a mix of promises and values) with the given mapper function with the signature (item, index, arrayLength) where item is the resolved value of a respective promise in the input array. If any promise in the input array is rejected the returned promise is rejected as well.

If the mapper function returns promises or thenables, the returned promise will wait for all the mapped results to be resolved as well.

The original array is not modified.

Parameters

  • values: Thenable
  • mapper: (item: R, index: number, arrayLength: number) => Promise.Thenable<U>

Returns

Promise

public static map(values: Thenable, mapper: (item: R, index: number, arrayLength: number) => U): Promise

Parameters

  • values: Thenable
  • mapper: (item: R, index: number, arrayLength: number) => U

Returns

Promise

public static map(values: Thenable, mapper: (item: R, index: number, arrayLength: number) => Promise.Thenable<U>): Promise

Parameters

  • values: Thenable
  • mapper: (item: R, index: number, arrayLength: number) => Promise.Thenable<U>

Returns

Promise

public static map(values: Thenable, mapper: (item: R, index: number, arrayLength: number) => U): Promise

Parameters

  • values: Thenable
  • mapper: (item: R, index: number, arrayLength: number) => U

Returns

Promise

public static map(values: Thenable[], mapper: (item: R, index: number, arrayLength: number) => Promise.Thenable<U>): Promise

Parameters

  • values: Thenable[]
  • mapper: (item: R, index: number, arrayLength: number) => Promise.Thenable<U>

Returns

Promise

public static map(values: Thenable[], mapper: (item: R, index: number, arrayLength: number) => U): Promise

Parameters

  • values: Thenable[]
  • mapper: (item: R, index: number, arrayLength: number) => U

Returns

Promise

public static map(values: Array<R>, mapper: (item: R, index: number, arrayLength: number) => Promise.Thenable<U>): Promise

Parameters

  • values: Array<R>
  • mapper: (item: R, index: number, arrayLength: number) => Promise.Thenable<U>

Returns

Promise

public static map(values: Array<R>, mapper: (item: R, index: number, arrayLength: number) => U): Promise

Parameters

  • values: Array<R>
  • mapper: (item: R, index: number, arrayLength: number) => U

Returns

Promise

public map(mapper: (item: Q, index: number, arrayLength: number) => Promise.Thenable<U>): Promise

Same as calling Promise.map(thisPromise, mapper). With the exception that if this promise is bound to a value, the returned promise is bound to that value too.

Parameters

  • mapper: (item: Q, index: number, arrayLength: number) => Promise.Thenable<U>

Returns

Promise

public map(mapper: (item: Q, index: number, arrayLength: number) => U): Promise

Parameters

  • mapper: (item: Q, index: number, arrayLength: number) => U

Returns

Promise

public static method(fn: Function): Function

Returns a new function that wraps the given function fn. The new function will always return a promise that is fulfilled with the original functions return values or rejected with thrown exceptions from the original function. This method is convenient when a function can sometimes return synchronously or throw synchronously.

Parameters

  • fn: Function

Returns

Function

public static noConflict(): Promise

This is relevant to browser environments with no module loader.

Release control of the Promise namespace to whatever it was before this library was loaded. Returns a reference to the library namespace so you can attach it to something else.

Returns

Promise

public nodeify(callback: (err: any, value?: R) => void): Promise

Register a node-style callback on this promise. When this promise is is either fulfilled or rejected, the node callback will be called back with the node.js convention where error reason is the first argument and success value is the second argument. The error argument will be null in case of success. Returns back this promise instead of creating a new one. If the callback argument is not a function, this method does not do anything.

Parameters

  • callback: (err: any, value?: R) => void

Returns

Promise

public nodeify(sink?: Array<any>)

Parameters

  • sink?: Array<any> optional

public static onPossiblyUnhandledRejection(handler: (reason: any) => any)

Add handler as the handler to call when there is a possibly unhandled rejection. The default handler logs the error stack to stderr or console.error in browsers.

Passing no value or a non-function will have the effect of removing any kind of handling for possibly unhandled rejections.

Parameters

  • handler: (reason: any) => any

public progressed(handler: (note: any) => any): Promise

Shorthand for .then(null, null, handler);. Attach a progress handler that will be called if this promise is progressed. Returns a new promise chained from this promise.

Parameters

  • handler: (note: any) => any

Returns

Promise

public static promisify(nodeFunction: Function, receiver?: any): Function

Returns a function that will wrap the given nodeFunction. Instead of taking a callback, the returned function will return a promise whose fate is decided by the callback behavior of the given node function. The node function should conform to node.js convention of accepting a callback as last argument and calling that callback with error as the first argument and success value on the second argument.

If the nodeFunction calls its callback with multiple success values, the fulfillment value will be an array of them.

If you pass a receiver, the nodeFunction will be called as a method on the receiver.

Parameters

  • nodeFunction: Function
  • receiver?: any optional

Returns

Function

public static promisifyAll(target: Object): Object

Promisifies the entire object by going through the object's properties and creating an async equivalent of each function on the object and its prototype chain. The promisified method name will be the original method name postfixed with Async. Returns the input object.

Note that the original methods on the object are not overwritten but new methods are created with the Async-postfix. For example, if you promisifyAll() the node.js fs object use fs.statAsync() to call the promisified stat method.

Parameters

  • target: Object

Returns

Object

public props(): Promise

Same as calling Promise.props(thisPromise). With the exception that if this promise is bound to a value, the returned promise is bound to that value too.

Returns

Promise

public static props(object: Promise): Promise

Like Promise.all but for object properties instead of array items. Returns a promise that is fulfilled when all the properties of the object are fulfilled. The promise's fulfillment value is an object with fulfillment values at respective keys to the original object. If any promise in the object rejects, the returned promise is rejected with the rejection reason.

If object is a trusted Promise, then it will be treated as a promise for object rather than for its properties. All other objects are treated for their properties as is returned by Object.keys - the object's own enumerable properties.

The original object is not modified.

Parameters

Returns

Promise

public static props(object: Object): Promise

Parameters

  • object: Object

Returns

Promise

public race(): Promise

Same as calling Promise.race(thisPromise, count). With the exception that if this promise is bound to a value, the returned promise is bound to that value too.

Returns

Promise

public static race(values: Thenable): Promise

Given an array, or a promise of an array, which contains promises (or a mix of promises and values) return a promise that is fulfilled or rejected as soon as a promise in the array is fulfilled or rejected with the respective rejection reason or fulfillment value.

Note If you pass empty array or a sparse array with no values, or a promise/thenable for such, it will be forever pending.

Parameters

Returns

Promise

public static race(values: Thenable): Promise

Parameters

Returns

Promise

public static race(values: Thenable[]): Promise

Parameters

Returns

Promise

public static race(values: Array<R>): Promise

Parameters

  • values: Array<R>

Returns

Promise

public reduce(reducer: (memo: U, item: Q, index: number, arrayLength: number) => Promise.Thenable<U>, initialValue?: U): Promise

Same as calling Promise.reduce(thisPromise, Function reducer, initialValue). With the exception that if this promise is bound to a value, the returned promise is bound to that value too.

Parameters

  • reducer: (memo: U, item: Q, index: number, arrayLength: number) => Promise.Thenable<U>
  • initialValue?: U optional

Returns

Promise

public reduce(reducer: (memo: U, item: Q, index: number, arrayLength: number) => U, initialValue?: U): Promise

Parameters

  • reducer: (memo: U, item: Q, index: number, arrayLength: number) => U
  • initialValue?: U optional

Returns

Promise

public static reduce(values: Thenable, reducer: (total: U, current: R, index: number, arrayLength: number) => Promise.Thenable<U>, initialValue?: U): Promise

Reduce an array, or a promise of an array, which contains a promises (or a mix of promises and values) with the given reducer function with the signature (total, current, index, arrayLength) where item is the resolved value of a respective promise in the input array. If any promise in the input array is rejected the returned promise is rejected as well.

If the reducer function returns a promise or a thenable, the result for the promise is awaited for before continuing with next iteration.

The original array is not modified. If no intialValue is given and the array doesn't contain at least 2 items, the callback will not be called and undefined is returned. If initialValue is given and the array doesn't have at least 1 item, initialValue is returned.

Parameters

  • values: Thenable
  • reducer: (total: U, current: R, index: number, arrayLength: number) => Promise.Thenable<U>
  • initialValue?: U optional

Returns

Promise

public static reduce(values: Thenable, reducer: (total: U, current: R, index: number, arrayLength: number) => U, initialValue?: U): Promise

Parameters

  • values: Thenable
  • reducer: (total: U, current: R, index: number, arrayLength: number) => U
  • initialValue?: U optional

Returns

Promise

public static reduce(values: Thenable, reducer: (total: U, current: R, index: number, arrayLength: number) => Promise.Thenable<U>, initialValue?: U): Promise

Parameters

  • values: Thenable
  • reducer: (total: U, current: R, index: number, arrayLength: number) => Promise.Thenable<U>
  • initialValue?: U optional

Returns

Promise

public static reduce(values: Thenable, reducer: (total: U, current: R, index: number, arrayLength: number) => U, initialValue?: U): Promise

Parameters

  • values: Thenable
  • reducer: (total: U, current: R, index: number, arrayLength: number) => U
  • initialValue?: U optional

Returns

Promise

public static reduce(values: Thenable[], reducer: (total: U, current: R, index: number, arrayLength: number) => Promise.Thenable<U>, initialValue?: U): Promise

Parameters

  • values: Thenable[]
  • reducer: (total: U, current: R, index: number, arrayLength: number) => Promise.Thenable<U>
  • initialValue?: U optional

Returns

Promise

public static reduce(values: Thenable[], reducer: (total: U, current: R, index: number, arrayLength: number) => U, initialValue?: U): Promise

Parameters

  • values: Thenable[]
  • reducer: (total: U, current: R, index: number, arrayLength: number) => U
  • initialValue?: U optional

Returns

Promise

public static reduce(values: Array<R>, reducer: (total: U, current: R, index: number, arrayLength: number) => Promise.Thenable<U>, initialValue?: U): Promise

Parameters

  • values: Array<R>
  • reducer: (total: U, current: R, index: number, arrayLength: number) => Promise.Thenable<U>
  • initialValue?: U optional

Returns

Promise

public static reduce(values: Array<R>, reducer: (total: U, current: R, index: number, arrayLength: number) => U, initialValue?: U): Promise

Parameters

  • values: Array<R>
  • reducer: (total: U, current: R, index: number, arrayLength: number) => U
  • initialValue?: U optional

Returns

Promise

public static reject(reason: any): Promise

Create a promise that is rejected with the given reason.

Parameters

  • reason: any

Returns

Promise

public static reject(reason: any): Promise

Parameters

  • reason: any

Returns

Promise

public static resolve(): Promise

Create a promise that is resolved with the given value. If value is a thenable or promise, the returned promise will assume its state.

Returns

Promise

public static resolve(value: Thenable): Promise

Parameters

Returns

Promise

public static resolve(value: R): Promise

Parameters

  • value: R

Returns

Promise

public return(): Promise

Convenience method for:

.then(function() { return value; });

in the case where value doesn't change its value. That means value is bound at the time of calling .return()

Alias .thenReturn(); for compatibility with earlier ECMAScript version.

Returns

Promise

public return(value: U): Promise

Parameters

  • value: U

Returns

Promise

public settle(): Promise

Same as calling Promise.settle(thisPromise). With the exception that if this promise is bound to a value, the returned promise is bound to that value too.

Returns

Promise

public static settle(values: Thenable): Promise

Given an array, or a promise of an array, which contains promises (or a mix of promises and values) return a promise that is fulfilled when all the items in the array are either fulfilled or rejected. The fulfillment value is an array of PromiseInspection instances at respective positions in relation to the input array.

original: The array is not modified. The input array sparsity is retained in the resulting array.

Parameters

Returns

Promise

public static settle(values: Thenable): Promise

Parameters

Returns

Promise

public static settle(values: Thenable[]): Promise

Parameters

Returns

Promise

public static settle(values: Array<R>): Promise

Parameters

  • values: Array<R>

Returns

Promise

public static some(values: Thenable, count: number): Promise

Initiate a competetive race between multiple promises or values (values will become immediately fulfilled promises). When count amount of promises have been fulfilled, the returned promise is fulfilled with an array that contains the fulfillment values of the winners in order of resolution.

If too many promises are rejected so that the promise can never become fulfilled, it will be immediately rejected with an array of rejection reasons in the order they were thrown in.

The original array is not modified.

Parameters

Returns

Promise

public static some(values: Thenable, count: number): Promise

Parameters

Returns

Promise

public static some(values: Thenable[], count: number): Promise

Parameters

Returns

Promise

public static some(values: Array<R>, count: number): Promise

Parameters

  • values: Array<R>
  • count: number

Returns

Promise

public some(count: number): Promise

Same as calling Promise.some(thisPromise). With the exception that if this promise is bound to a value, the returned promise is bound to that value too.

Parameters

  • count: number

Returns

Promise

public static spawn(generatorFunction: Function): Promise

Spawn a coroutine which may yield promises to run asynchronous code synchronously. This feature requires the support of generators which are drafted in the next version of the language. Node version greater than 0.11.2 is required and needs to be executed with the --harmony-generators (or --harmony) command-line switch.

Parameters

  • generatorFunction: Function

Returns

Promise

public spread(onFulfill: Function, onReject?: (reason: any) => Promise.Thenable<U>): Promise

Like calling .then, but the fulfillment value or rejection reason is assumed to be an array, which is flattened to the formal parameters of the handlers.

Parameters

  • onFulfill: Function
  • onReject?: (reason: any) => Promise.Thenable<U> optional

Returns

Promise

public spread(onFulfill: Function, onReject?: (reason: any) => U): Promise

Parameters

  • onFulfill: Function
  • onReject?: (reason: any) => U optional

Returns

Promise

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

Promises/A+ .then() with progress handler. Returns a new promise chained from this promise. The new promise will be rejected or resolved dedefer on the passed fulfilledHandler, rejectedHandler and the state of this promise.

Parameters

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

Returns

Promise

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

Parameters

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

Returns

Promise

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

Parameters

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

Returns

Promise

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

Parameters

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

Returns

Promise

public thenReturn(): Promise

Returns

Promise

public thenReturn(value: U): Promise

Parameters

  • value: U

Returns

Promise

public thenThrow(reason: Error): Promise

Parameters

  • reason: Error

Returns

Promise

public throw(reason: Error): Promise

Convenience method for:

.then(function() { throw reason; }); Same limitations apply as with .return().

Alias .thenThrow(); for compatibility with earlier ECMAScript version.

Parameters

  • reason: Error

Returns

Promise

public timeout(ms: number, message?: string): Promise

Returns a promise that will be fulfilled with this promise's fulfillment value or rejection reason. However, if this promise is not fulfilled or rejected within ms milliseconds, the returned promise is rejected with a Promise.TimeoutError instance.

You may specify a custom error message with the message parameter.

Parameters

  • ms: number
  • message?: string optional

Returns

Promise

public toJSON(): Object

This is implicitly called by JSON.stringify when serializing the object. Returns a serialized representation of the Promise.

Returns

Object

public toString(): string

Convert to String.

Returns

string

public static try(fn: () => Promise.Thenable<R>, args?: Array<any>, ctx?: any): Promise

Start the chain of promises with Promise.try. Any synchronous exceptions will be turned into rejections on the returned promise.

Note about second argument: if it's specifically a true array, its values become respective arguments for the function call. Otherwise it is passed as is as the first argument for the function call.

Alias for attempt(); for compatibility with earlier ECMAScript version.

Parameters

  • fn: () => Promise.Thenable<R>
  • args?: Array<any> optional
  • ctx?: any optional

Returns

Promise

public static try(fn: () => R, args?: Array<any>, ctx?: any): Promise

Parameters

  • fn: () => R
  • args?: Array<any> optional
  • ctx?: any optional

Returns

Promise

public uncancellable(): Promise

Create an uncancellable promise based on this promise.

Returns

Promise