Skip to main content
Version: 8.1

runAsync

Asynchronously runs a BarTender integration. This is the main method for triggering actions on the BarTender server.

important

Sibling method of system.bartender.runBlocking.

Syntax

system.bartender.runAsync(connectionName, data)

Parameters

TypeParameterDescription
StringconnectionNameThe 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, StringdataThe 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

SignatureReturnsDescription
getFuture()CompletableFutureReturns the raw underlying CompletableFuture.
cancel()BooleanCancels the completion of this future.
isDone()BooleanChecks if the future is complete.
then(callback)PyCompletableFutureReturn a new PyCompletableFuture that wraps this one's return value in a Python callable.
handleException(callback)PyCompletableFutureReturn a new PyCompletableFuture that will run the provided callback in the event of an exception, to attempt graceful error handling.
whenComplete(callback)NoneCall callback, asynchronously, whenever this future completes.
warning

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.

tip

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:

Run a function when a BarTender trigger completes
# 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)

Examples