The JSDO allows most asynchronous methods to return results using ES6 Promises (if available) in addition to any results returned using named events (see Named events). This Promise support is available for the following standard JSDO methods:

  • fill( )
  • invoke( )
  • saveChanges( )

Asynchronous JSDO methods return ES6 Promises. You can call methods on the returned Promise to register functions that will be called depending on whether the Promise resolves or rejects. Each entry for the JSDO methods in the JSDO properties, methods, and events reference show several examples of Promises.

The fill() and saveChanges()methods 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.

Each Promise will be resolved or rejected with an object that contains the outcome of the operation. The following functions return Promises:

  • fill()
  • invoke()
  • saveChanges()

The objects returned by Promises contain the following fields:

  • jsdo
  • success
  • request

This allows you to share callbacks for both subscription to appropriate named events and registration by appropriate Promise methods. 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 in the JSDO properties, methods, and events reference.