WaitForAnyJobs
WaitForAnyJobs
function to instruct a main process to wait for
any specified asynchronously executed processes to complete before continuing the main
process.
Syntax
WaitForAnyJobs(JobID1, JobID2, JobID3...);
Argument |
Description |
---|---|
JobID1, JobID2, JobID3... |
The ID of a process executed asynchronously from within the main process. |
Example
JobId1 = RunProcess(`async_process_1`);
JobId2 = RunProcess(`async_process_2`);
#*** Do something else in the process
ret = WaitForAnyJobs(JobId1, JobId2);
A main process can execute other process asynchronously by using the RunProcess
function, as shown in this example where two asynchronous processes are executed.
The RunProcess
function returns a JobId in string format if it successfully
launches an asynchronous process. Later on in the main process, the JobIds can be provided as
arguments to the WaitForAnyJobs
function.
In this example,WaitForAnyJobs(JobId1, JobId2)
blocks the main process and waits
for either JobId1 (async_process_1) or JobId2 (async_process_2) to finish before continuing
the main process.
The return value of WaitForAnyJobs
is the completed asynchronous process JobID.
In this example, the return value is either JobId1
or JobId2
,
whichever finishes first. The return value is an empty string if the function could not perform the
wait properly; in this case the execution status of the asynchronous processes is unknown.