Module promise

Index

Interfaces

Classes

Functions

Functions

asap(value: any, callback: (value: any) => any, opt_errback?: (error: any) => any)

Invokes the appropriate callback function as soon as a promised {@code value} is resolved. This function is similar to {@code webdriver.promise.when}, except it does not return a new promise.

Parameters

  • value: any

    The value to observe.

  • callback: (value: any) => any

    The function to call when the value is resolved successfully.

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

    The function to call when the value is rejected.

checkedNodeCall(fn: (error: any, value: any) => any): Promise

Wraps a function that is assumed to be a node-style callback as its final argument. This callback takes two arguments: an error value (which will be null if the call succeeded), and the success value as the second argument. If the call fails, the returned promise will be rejected, otherwise it will be resolved with the result.

Parameters

  • fn: (error: any, value: any) => any

    The function to wrap.

Returns

Promise

A promise that will be resolved with the result of the provided function's callback.

controlFlow(): ControlFlow

Returns

ControlFlow

The currently active control flow.

createFlow(callback: (flow: webdriver.promise.ControlFlow) => any): Promise

Creates a new control flow. The provided callback will be invoked as the first task within the new flow, with the flow as its sole argument. Returns a promise that resolves to the callback result.

Parameters

  • callback: (flow: webdriver.promise.ControlFlow) => any

    The entry point to the newly created flow.

Returns

Promise

A promise that resolves to the callback result.

defer(opt_canceller?: any): Deferred

Creates a new deferred object.

Parameters

  • opt_canceller?: any optional

    Function to call when cancelling the computation of this instance's value.

Returns

Deferred

The new deferred object.

delayed(ms: number): Promise

Creates a promise that will be resolved at a set time in the future.

Parameters

  • ms: number

    The amount of time, in milliseconds, to wait before resolving the promise.

Returns

Promise

The promise.

fulfilled(opt_value?: any): Promise

Creates a promise that has been resolved with the given value.

Parameters

  • opt_value?: any optional

    The resolved value.

Returns

Promise

The resolved promise.

fullyResolved(value: any): Promise

Returns a promise that will be resolved with the input value in a fully-resolved state. If the value is an array, each element will be fully resolved. Likewise, if the value is an object, all keys will be fully resolved. In both cases, all nested arrays and objects will also be fully resolved. All fields are resolved in place; the returned promise will resolve on {@code value} and not a copy.

Warning: This function makes no checks against objects that contain cyclical references:

var value = {}; value['self'] = value; webdriver.promise.fullyResolved(value); // Stack overflow.

Parameters

  • value: any

    The value to fully resolve.

Returns

Promise

A promise for a fully resolved version of the input value.

isPromise(value: any): boolean

Determines whether a {@code value} should be treated as a promise. Any object whose "then" property is a function will be considered a promise.

Parameters

  • value: any

    The value to test.

Returns

boolean

Whether the value is a promise.

rejected(opt_reason?: any): Promise

Creates a promise that has been rejected with the given reason.

Parameters

  • opt_reason?: any optional

    The rejection reason; may be any value, but is usually an Error or a string.

Returns

Promise

The rejected promise.

setDefaultFlow(flow: ControlFlow)

Changes the default flow to use when no others are active.

throws

{Error} If the default flow is not currently active.

Parameters

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

Registers an observer on a promised {@code value}, returning a new promise that will be resolved when the value is. If {@code value} is not a promise, then the return promise will be immediately resolved.

Parameters

  • value: any

    The value to observe.

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

    The function to call when the value is resolved successfully.

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

    The function to call when the value is rejected.

Returns

Promise

A new promise.