WaitAsynchronous (Daemon function)

From m204wiki
Jump to navigation Jump to search

Wait for an asynchronous result (Daemon class)


This callable method waits for the completion of the RunAsynchronously or ContinueAsynchronously processing on a daemon thread, and it retrieves various outputs from those methods.

Syntax

[%sl =] daemon:WaitAsynchronous[( [[Output=] object], [Info= object])] Throws DaemonLost, IncorrectDaemonState

Syntax terms

%sl If specified, a Stringlist object that contains the terminal output from the command or commands run on the daemon thread.
daemon A Daemon object.
Output An output %variable which is set to the object returned by the daemon thread using the ReturnObject subroutine invoked on the daemon thread. This object is set by deep copy and not by reference, so the class of object must be deep copyable, as described in "Copying objects".

Because object is an output variable, it cannot itself be contained inside an object: that is, it must be a local or a common %variable.

Info An optional, name required argument that indicates a second output %variable which is set to the object returned by the daemon thread using the ReturnInfoObject subroutine invoked on the daemon thread. This object is set by deep copy and not by reference, so the class of this argument must be deep copyable.

Because this is an output argument, it cannot itself be contained inside an object: that is, it must be a local or a common %variable.

Exceptions

This subroutine can throw the following exception:

DaemonLost If the daemon object is lost (probably restarted), a DaemonLost exception is thrown. This exception will only be thrown in Sirius Mods version 7.2 and later.

Usage notes

  • WaitAsynchronous was introduced in Sirius Mods version 7.0.
  • If WaitAsynchronous is issued against a Daemon object that is not currently running asynchronously (that is, if RunAsynchronously was not issued against it), the request is canceled. Note that this does not mean that the Daemon must actually still be running — if the daemon thread has run all the commands in the RunAsynchronously call, not only is WaitAsynchronous allowed, it is required before anything else can be done with the Daemon. And, in any case, it's the only way of retrieving the outputs from the asynchronous request.
  • This is an example WaitAsynchronous call:

    %daem:runAsynchronously(%commands) ... %strlist = %daem:waitAsynchronous(%list2)

  • The output Stringlist and parameters from WaitAsynchronous are identical to the output Stringlist and parameters for the Run method, so see "Daemon class" for more information on and examples of output Stringlists and objects.
  • The inputs and outputs from the combination of RunAsynchronously and WaitAsynchronous are identical to the inputs and outputs from the Run method. As such, it should be a relatively simple task to split a Run invocation into RunAsynchronously and WaitAsynchronous invocations, allowing the daemon processing to be performed in parallel with parent thread processing or the processing on another daemon thread. For example, if a request has the following statements:

    %out1 = %daem1:run(%cmds1, %inobj1, %outobj1) %out2 = %daem2:run(%cmds2, %inobj2, %outobj2)

    The statements can be easily split up into the following, and the processing on the two Daemons would be performed in parallel with each other:

    %daem1:runAsynchronously(%cmds1, %inobj1) %daem2:runAsynchronously(%cmds2, %inobj2) %out1 = %daem1:waitAsynchronous(%outobj1) %out2 = %daem2:waitAsynchronous(%outobj2)

    Note that this will buy nothing if the requests are CPU-intensive and the request is not running with AMPSUBS > 0 (requires MP/204). Note also that if the daemons hold or require record locks that might conflict with each other, such a split will not work. Finally, since RunAsynchronously is not allowed for a transactional daemon, such a split is not feasible for transactional daemons.

  • For more information about asynchronous daemons, see "Asynchronous and Independent daemons".

See also