WinJS.Promise object

Applies to Windows and Windows Phone

Provides a mechanism to schedule work to be done on a value that has not yet been computed. It is an abstraction for managing interactions with asynchronous APIs.

For more information about asynchronous programming, see Asynchronous programming. For more information about promises in JavaScript, see Asynchronous programming in JavaScript.

Syntax


var aPromise = new WinJS.Promise(init, onCancel);

Members

The Promise object has these types of members:

Constructors

The Promise object has these constructors.

ConstructorDescription
Promise

A promise provides a mechanism to schedule work to be done on a value that has not yet been computed. It is a convenient abstraction for managing interactions with asynchronous APIs.

For more information about asynchronous programming, see Asynchronous programming. For more information about promises in JavaScript, see Asynchronous programming in JavaScript.

 

Events

The Promise object has these events.

EventDescription
onerror

Occurs when there is an error in processing a promise.

 

Methods

The Promise object has these methods.

MethodDescription
addEventListener

Adds an event listener for the promise.

cancel

Attempts to cancel the fulfillment of a promised value. If the promise hasn't already been fulfilled and cancellation is supported, the promise enters the error state with a value of Error("Canceled").

dispatchEvent

Raises an event of the specified type and properties.

done

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. After the handlers have finished executing, this function throws any error that would have been returned from then as a promise in the error state.

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

removeEventListener

Removes an event listener from the control.

then

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:

 

Requirements

Minimum supported client

Windows 8 [Windows Store apps only]

Minimum supported server

Windows Server 2012 [Windows Store apps only]

Minimum supported phone

Windows Phone 8.1

Namespace

WinJS

Library

Base.js

 

 

Show:
© 2014 Microsoft