Class Promise

Represents the eventual value of a completed operation. Each promise may be in one of three states: pending, resolved, or rejected. Each promise starts in the pending state and may make a single transition to either a fulfilled or failed state.

This class is based on the Promise/A proposal from CommonJS. Additional functions are provided for API compatibility with Dojo Deferred objects.

see

http://wiki.commonjs.org/wiki/Promises/A

Hierarchy

Index

Constructor methods

Methods

Constructor methods

constructor(): Promise

constructor
see

http://wiki.commonjs.org/wiki/Promises/A

Returns

Promise

Methods

public addBoth(callback: (value: any) => any, opt_self?: any): Promise

Registers a function to be invoked when this promise is either rejected or resolved. This function is provided for backwards compatibility with the Dojo Deferred API.

Parameters

  • callback: (value: any) => any

    The function to call when this promise is either resolved or rejected. The function should expect a single argument: the resolved value or rejection error.

  • opt_self?: any optional

    The object which |this| should refer to when the function is invoked.

Returns

Promise

A new promise which will be resolved with the result of the invoked callback.

public addCallback(callback: (value: any) => any, opt_self?: any): Promise

Registers a function to be invoked when this promise is successfully resolved. This function is provided for backwards compatibility with the Dojo Deferred API.

Parameters

  • callback: (value: any) => any

    The function to call if this promise is successfully resolved. The function should expect a single argument: the promise's resolved value.

  • opt_self?: any optional

    The object which |this| should refer to when the function is invoked.

Returns

Promise

A new promise which will be resolved with the result of the invoked callback.

public addCallbacks(callback: (value: any) => any, errback: (error: any) => any, opt_self?: any): Promise

An alias for {@code webdriver.promise.Promise.prototype.then} that permits the scope of the invoked function to be specified. This function is provided for backwards compatibility with the Dojo Deferred API.

Parameters

  • callback: (value: any) => any

    The function to call if this promise is successfully resolved. The function should expect a single argument: the promise's resolved value.

  • errback: (error: any) => any

    The function to call if this promise is rejected. The function should expect a single argument: the rejection reason.

  • opt_self?: any optional

    The object which |this| should refer to when the function is invoked.

Returns

Promise

A new promise which will be resolved with the result of the invoked callback.

public addErrback(errback: (error: any) => any, opt_self?: any): Promise

Registers a function to be invoked when this promise is rejected. This function is provided for backwards compatibility with the Dojo Deferred API.

Parameters

  • errback: (error: any) => any

    The function to call if this promise is rejected. The function should expect a single argument: the rejection reason.

  • opt_self?: any optional

    The object which |this| should refer to when the function is invoked.

Returns

Promise

A new promise which will be resolved with the result of the invoked callback.

public cancel(reason: any)

Cancels the computation of this promise's value, rejecting the promise in the process.

Parameters

  • reason: any

    The reason this promise is being cancelled. If not an {@code Error}, one will be created using the value's string representation.

public isPending(): boolean

Returns

boolean

Whether this promise's value is still being computed.

public then(opt_callback?: (value: any) => any, opt_errback?: (error: any) => any): Promise

Registers listeners for when this instance is resolved. This function most overridden by subtypes.

Parameters

  • opt_callback?: (value: any) => any optional

    The function to call if this promise is successfully resolved. The function should expect a single argument: the promise's resolved value.

  • opt_errback?: (error: any) => any optional

    The function to call if this promise is rejected. The function should expect a single argument: the rejection reason.

Returns

Promise

A new promise which will be resolved with the result of the invoked callback.