Asynchronous vs. synchronous method execution
- Last Updated: October 29, 2020
- 2 minute read
- OpenEdge
- Version 12.2
- Documentation
You can execute invocation methods either asynchronously (the default behavior) or synchronously, depending on how you call them. A JSDO provides two basic mechanisms for calling an invocation method:
- Calling the method by name — Invoking the method on the JSDO instance like any other JSDO method. This allows you to call the method asynchronously or synchronously according to a parameter that you pass, with all asynchronous results handled by event callbacks.
- Passing the method as a parameter to the JSDO
invoke( )method — Invoking theinvoke( )method on the JSDO instance, passing as parameters the name of the method and an object containing properties whose names match the names of the input parameters defined for the server method that implements the Invoke operation. This allows you to call the invocation method asynchronously only, with results handled either (or both) using event callbacks or callbacks that you register using a Promise object returned as the value of theinvoke( )method.
If you call the invocation method by name, along with an optional object
parameter containing properties that match any input parameters defined for the implementing
server method, you can pass a second optional boolean
parameter that specifies the execution mode. A value of true
(the default) for this second parameter specifies asynchronous execution; for synchronous
execution, set the parameter to false.
To process the results of an asynchronous method call, you can subscribe an
event-handler callback function to the afterInvoke event, or
if you use the invoke( ) method, register callbacks on the returned
Promise object by calling any of the available Promise methods (see Promises). All Invoke operation callbacks have the same signature,
which includes a returned request object from which you can return results by accessing its
response property.
For a synchronous call, you do not use callbacks, but access results through
the response property of the request object that is returned
as the value of the invocation method.