Topic: APLX Help : Multi-tasking support : Communication between child and parent tasks
[ Previous | Next | Contents | Index | APL Home ]

www.microapl.co.uk

Communication between child and parent tasks


Once a child task is running, events are used to communicate between the child and its parent. These events can arise automatically, or more usually by explicit program action. They are used to trigger the execution of a callback function in the receiving task. (Note: As with all callbacks in APLX, the actual callback is run in a ⎕WE (wait for events) statement).

The automatic events occur when the state of the child task changes. They are as follows (in each case, ⎕EV[6] in index origin 1 will contain the unique task ID, as returned by the taskid property):

  • When the state of the child task changes from executing to awaiting input, an onReady event is triggered in the parent's task object. You can associate a callback with this, for example to pass the next command to the child task:

          ChildTask.onReady←'NEXTCMD'

    This would cause the NEXTCMD function to be run when the child task is ready for the next command to be sent to it using the Execute method.

  • When an untrapped error occurs during function execution (but not desk-calculator mode) in the child task, an onError event is triggered in the parent's task object. You can associate a callback with this, for example to write the error to a diagnostic log:

          ChildTask.onError←'ERROR_HANDLER'

    This would cause the ERROR_HANDLER function to be run when an error is encountered in the child task. The error message (in the same format as ⎕ERM) will be available in ⎕WARG during the callback. (If you have an onReady callback defined as well, this will be also be triggered, after onError).

  • When the child task is about to execute an expression or command (either typed by the user, or under program control) an onExecute event is triggered in the parent's task object. During the callback, ⎕WARG contains the command or expression which is about to be executed, as a character vector. This can be used for example to write an APL tutorial application when the parent task can see what the user is entering in the child-task session window.
  • Finally, when the child task is about to terminate for any reason, an onClose event is triggered in the parent's task object.

Topic: APLX Help : Multi-tasking support : Communication between child and parent tasks
[ Previous | Next | Contents | Index | APL Home ]