Using JSDOs to create mobile and web clients : JSDO overview : Asynchronous and synchronous execution : Asynchronous execution using Promises
  
Asynchronous execution using Promises
The JSDO allows most asynchronous methods to return results using jQuery Promises (if available) in addition to any results returned using named events (see Asynchronous execution using named events). This Promise support is available for the following standard JSDO methods:
*fill( )
*invoke( )
*saveChanges( )
A Promise is a deferred object that a supported asynchronous method returns immediately as its value when you call it. You can then call methods on the returned Promise object to register callback functions that execute for the asynchronous method when results are available depending on conditions associated with each Promise object method. You provide your own code to handle the results returned by each callback that you register, much like the code you provide in a named event handler callback.
Note: To use Promises to return asynchronous JSDO results, your environment must support jQuery Promises or the exact equivalent. Note also that jQuery Promises are both required and available to return asynchronous JSDO results when you access resources of a Progress Data Object Service using the JSDO dialect of the Kendo UI DataSource. (The jQuery libraries are included with Kendo UI.) For more information, see Using the JSDO dialect of the Kendo UI DataSource .
The primary Promise methods for use with a JSDO object include done( ), fail( ), and always( ), which allow you to separately handle the successful, unsuccessful, and all results (respectively) of a JSDO method execution. Note that for any given JSDO method, the parameter lists for all Promise method callbacks have the same signature. Note also that the callback for the always( ) method executes with the same values in its parameter list as the callback for the done( ) or fail( ) method, whichever one executes with results. The descriptions of the JSDO methods that return results using Promises show several examples of their use. For more information on the jQuery implementation of Promises and the additional Promise methods that are available, see the jQuery topics at the following Web locations:
*Category: Deferred Objecthttp://api.jquery.com/category/deferred-object/
*Promise Objecthttp://api.jquery.com/Types/#Promise
*.promisehttp://api.jquery.com/promise/
The fill( ) and saveChanges( )methods similarly allow you to return their asynchronous results using either or both named events and Promises. Note that directly calling a custom JSDO invocation method asynchronously only returns results using named events. To return asynchronous results of an invocation method using either or both named events and Promises, you must call the invocation method using the API provided by the standard JSDO invoke( ) method.
The signatures for Promise callbacks are identical to the signatures of the callbacks for the after* event for each asynchronous JSDO method that supports Promises as follows:
*fill( )afterFill event callback signature
*invoke( )afterInvoke event callback signature
*saveChanges( )afterSaveChanges event callback signature
This allows you to share callbacks for both subscription to appropriate named events and registration by appropriate Promise methods.
Note that when using both named events and Promises to return results for a given asynchronous method, the results are returned to callbacks in the following general order:
1. To before* event callbacks
2. To after* event callbacks
3. to Promise callbacks.
For a more detailed description of results handling for named events and Promises, see the description of each JSDO method that supports Promises.