Поделиться через


Promise.then method

Allows you to specify the work to be done on the fulfillment of the promised value, the error handling to be performed if the promise fails to fulfill a value, and the handling of progress notifications along the way.

For more information about the differences between then and done, see the following topics:

Syntax

promise.then(onComplete, onError, onProgress).done( /* Your success and error handlers */ );

Parameters

  • onComplete
    Type: Function

    The function to be called if the promise is fulfilled successfully with a value. The value is passed as the single argument. If the value is null, the value is returned. The value returned from the function becomes the fulfilled value of the promise returned by then. If an exception is thrown while this function is being executed, the promise returned by then moves into the error state.

  • onError
    Type: Function

    The function to be called if the promise is fulfilled with an error. The error is passed as the single argument. In different cases this object may be of different types, so it is necessary to test the object for the properties you expect. If the error is null, it is forwarded. The value returned from the function becomes the value of the promise returned by the then function.

  • onProgress
    Type: Function

    The function to be called if the promise reports progress. Data about the progress is passed as the single argument. Promises are not required to support progress.

Return value

Type: Promise

The promise whose value is the result of executing the onComplete function.

Requirements

Minimum WinJS version

WinJS 1.0

Namespace

WinJS.Promise

See also

Promise