|
<< Click to Display Table of Contents >> Navigation: 3. Script Language > Internet and Network > MCP. - MCP (Model-Context Protocol) server operations > !Server-Operations - Commands for interacting with a running MCP server (signals, actions) > MCP. - MCP Server Operations |
SPR Script Language
HTP.WaitForResult
Waits for a parallel script to finish and return a result.
Intention
After launching a script with HTP.RunScript, the parent script continues running without waiting. The HTP.WaitForResult command pauses the parent script until the child script either finishes (by calling HTP.ReturnResult), crashes, or times out. This is the essential command for synchronizing two scripts and retrieving data from a parallel task.
It also provides robust monitoring; it can detect if the child process has terminated unexpectedly and can automatically terminate a hung process if it exceeds the specified timeout.
Illustration
📞 Phone Call: You've sent your worker on a task (HTP.RunScript). Now you wait by the phone (HTP.WaitForResult) for them to call back with the answer. If they don't call back in time, you hang up (timeout). If the line goes dead, you know something went wrong (crash).
Syntax
HTP.WaitForResult|$$RES[|$$PID][|$$TIO]
Parameter Explanation
P1 - $$RES - (Variable, Required)
The variable that will receive the result string from the child script. The command waits until the content of this variable is changed by the child process.
P2 - $$PID - (Variable, Optional)
The variable containing the Process ID of the child script to monitor. If omitted, it defaults to the last PID launched by HTP.RunScript.
P3 - $$TIO - (Numeric, Optional)
The timeout in milliseconds. If the child script does not return a result within this time, it will be terminated. Defaults to 300,000 (5 minutes).
Examples
'***********************************
' HTP.WaitForResult - Sample 1: Get a Result from a Child Script
'***********************************
' Child script that calculates a value and returns it
VAR.$$cod=CAL.$$aaa=5*5$crlf$HTP.ReturnResult|$$aaa
' Parent script launches the child
HTP.RunScript|$$cod|$$pid
' Initialize the result variable
VAR.$$res=
' Wait for the result and get the status code from the stack
HTP.WaitForResult|$$res|$$pid
VAR.$$sts=$tos$
IVV.$$sts=0 ' 0 = Success
MBX.Child script succeeded! Result: $$res
ELS.
MBX.Child script failed! Status: $$sts
EIF.
ENR.
'
Remarks
- This command is blocking; it will pause the execution of the parent script.
- It returns a status code on the top of the stack (TOS):
0: Success. A result was received in the $$RES variable.
1: Timeout. The child process was terminated.
2: Process Crash. The child process terminated without returning a result.
See also: