Skip to main content
Version: 8.1

system.util.sendRequestAsync

This function is used in Python Scripting.

Description​

This function sends a message to the Gateway and expects a response. Works in a similar manner to the sendRequest function, except sendRequestAsync will send the request and then immediately return a handle for it. The Request handle has the following methods:

  • get() - Block for result, throw an exception on failure.
  • cancel() - Cancel the request. Any completion callback will be called with CancellationException
  • block() - Like get(), but will return a Boolean True or False once complete, indicating completion success. If False, call getError() to get the exception object.
  • getError() - Returns the error result or null. Similar to get(), in that this will block for a result.
  • onSuccess(PyFunction) - Will set a function to run on a successful completion callback or set a new one if one was already defined in the sendRequestAsync call.
  • onError(PyFunction) - Will set a function to run on a failed completion callback or set a new one if one was already defined in the sendRequestAsync call.

Client Permission Restrictions​

This scripting function has no Client Permission restrictions.

Syntax​

system.util.sendRequestAsync(project, messageHandler, [payload], [remoteServer], [timeoutSec], [onSuccess], [onError])

Parameters​

TypeParameterDescription
StringprojectThe name of the project containing the message handler.
StringmessageHandlerThe name of the message handler that will fire upon receiving a message.
Dictionary[String, Any]payloadA dictionary which will get passed to the message handler. Use "payload" in the message handler to access dictionary variables. [optional]
StringhostNameLimits the message delivery to the client that has the specified network host name. [optional]
StringremoteServerA string representing the target Gateway server name. The message will be delivered to the remote Gateway over the Gateway Network. Upon delivery, the message is distributed to the local Gateway and clients as per the other parameters. [optional]
StringtimeoutSecThe number of seconds before the sendRequest call times out. [optional]
CallableonSuccessShould take one argument, which will be the result from the message handler. Callback functions will be executed on the GUI thread, similar to system.util.invokeLater. [optional]
CallableonErrorShould take one argument, which will be the exception encountered. Callback functions will be executed on the GUI thread, similar to system.util.invokeLater. [optional]

Returns​

Request Handle - The Request object that can be used while waiting for the message handler callback.

Scope​

Gateway, Vision Client, Perspective Session

Code Examples​

Example #1
# This will call the message handler 'test', and will return a handle into myHandle.
# We then call get() on myHandle, which will block the script and will wait for a return or throw an exception on failure.
myHandle = system.util.sendRequestAsync(project='ACME', messageHandler='test', payload={'number':55})
myHandle.get()
Example #2
# This will call the message handler 'test', and will return a handle into myHandle.
# In this example, we will define a function to run when the message handler has successfully finished, using the onSuccess function on the Request Handle.

# Note that function accepts a single argument for the message.
def successFunc(message):
system.gui.messageBox("Successfully finished: %s" % message)

# We're specifying that the request should timeout after 5 seconds.
myHandle = system.util.sendRequestAsync(project='ACME', messageHandler='test', payload={'number':55}, timeoutSec=5)

# Call the Request Handler's onSuccess function, passing in successFunc.
myHandle.onSuccess(successFunc)