runAsync
Asynchronously runs a BarTender integration. This is the main method for triggering actions on the BarTender server.
Sibling method of system.bartender.runBlocking
.
Syntax
system.bartender.runAsync(connectionName, data)
Parameters
Type | Parameter | Description |
---|---|---|
String | connectionName | The name of the BarTender connection to trigger. The function will throw an error if the specified connectionName does not exist on the host gateway. |
BTXMLScript, PyDictionary, String | data | The input data to provide the BarTender integration. |
Returns
PyCompletableFuture<QualifiedResponse> - A PyCompletableFuture containing the response from the integration.
Scope
Gateway, Designer, Client, Perspective Session
PyCompletableFuture
In order to execute asynchronously this function returns a PyCompletableFuture.
This is wrapper around a Java CompletableFuture
with convenience functions for interacting with Python scripting. PyCompletableFuture functions very similarly to the Promise objects returned from system.net.httpClient
calls.
Methods
Signature | Returns | Description |
---|---|---|
getFuture() | CompletableFuture | Returns the raw underlying CompletableFuture . |
cancel() | Boolean | Cancels the completion of this future. |
isDone() | Boolean | Checks if the future is complete. |
then(callback) | PyCompletableFuture | Return a new PyCompletableFuture that wraps this one's return value in a Python callable. |
handleException(callback) | PyCompletableFuture | Return a new PyCompletableFuture that will run the provided callback in the event of an exception, to attempt graceful error handling. |
whenComplete(callback) | None | Call callback, asynchronously, whenever this future completes. |
The response handlers (then
, handleException
and whenComplete
all run on asynchronous threads. Do not attempt to read or write property values in these callbacks or client deadlocking will occur.
Use system.util.invokeLater
to safely read and write property values from a callback.
A thorough explanation of CompletableFuture
is outside the scope of this manual, but here are a few common examples:
# Show a message box on the screen with the response value.
# (Note the use of invokeLater in order to execute on the GUI thread)
# If an exception occurs, rethrow it.
def useResponse(response, ex):
def showMessage():
if ex:
raise ex
else:
system.gui.messageBox(response.value)
system.util.invokeLater(showMessage)
# Run the trigger asynchronously
# When the result completes, do something with the response
result = system.bartender.runAsync("BarTender", {"param": "Value"})
result.whenComplete(useResponse)