Windows Dev Center

Este conteúdo não está disponível em seu idioma, mas aqui está a versão em inglês.

WinJS.Promise constructor

Applies to Windows and Windows Phone

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.


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



Type: Function

The function that is called during construction of the Promise that contains the implementation of the operation that the Promise will represent. This can be synchronous or asynchronous, depending on the nature of the operation. Note that placing code within this function does not automatically run it asynchronously; that must be done explicitly with other asynchronous APIs such as setImmediate, setTimeout, requestAnimationFrame, and the Windows Runtime asynchronous APIs.

The init function is given three arguments:

  • completeDispatch: The init code should invoke this when the operation is complete, passing the operation's results as an argument.
  • errorDispatch: The init code should invoke this function when an error occurs, which will place the promise into the error state. The argument to errorDispatch should be an object created with WinJS.Promise.ErrorFromName.
  • progressDispatch: If the operation wishes to support progress, The init code should invoke this function periodically while the operation is underway, passing an intermediate result as the argument.

This parameter is optional.


Type: Function

The function to call if a consumer of this promise wants to cancel its undone work. Promises are not required to support cancellation.


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





See also




© 2015 Microsoft