<< Click to Display Table of Contents >> Navigation: 3. Script Language > Background Operation > WRS. - Wait for Result |
MiniRobotLanguage (MRL)
WRS. - Wait for Result
Wait for Result from Background Operation
Intention
This command will wait until:
- a Background Operation / Parallel-Robot has ended
- there is an incoming Result from an Operation / Parallelrobot
- using for example PRS.
When waiting for an "Result", the command will still react if the given process ends.
Using "Background Operations" means, that your Script execution goes on, while the Robot is doing something in the background.
To wait for a background operation to be finished, the WRS.-command was made.
It can also collect the Results of multiple background operations.
The system works like this:
1. Start a background operation and get a "ticket number"
2. keep the ticket number in a variable
3. do whatever you want ...
4. and call WRS. with that "ticket number" as parameter
5. WRS. will wait until the background Operation has finished
6. Call GRS. to get the result of the background operation
Hint: If you have just one background operation running, you do not need to specify an ticket number. The system always remembers the and uses the ticket number from the last background operation.
Example:
' Assume that a file "?path\MailConfig.dat"
' is available
SMP.
' It makes mostly sense with attachements
' SMP.attachment=?path\Send-Mail.zip
' Send the Mail, get the ticket number
SMB.
' If we do not specify a ticket number,
' WRS. will automatically remember the last ticket number
' and use it.
WRS.
' If we do not specify a ticket number,
' GRS. will automatically remember the last ticket number
' and use it.
GRS.
DBP.$$000
' If we do not specify a ticket number,
' DRS. will automatically remember the last ticket number
' and use it.
' DRS. free's the Memory location that was used to hold the
' Result of the background operation.
DRS.
ENR.
How do i know that the operation was finished and there is an Result available?
As said, you can use WRS. And that is maybe the best version. Besides WRS. , there are several more ways to find that out.
The easiest is to simply wait for the background Operation to finish, using the WRS.-command (Wait for Result).
You can also use the IRS. / NRS. - Conditional statement.
And theoretically you could call GRS. and check the timeout-flag after that.
If the timeout-flag was set after a call to GRS. it was set, there was no result available.
How do i collect results from multiple parallel running robots/operations?
Here is an example:
PRR.
GUT.Please give Result for Robot 1
PRS.|Result from Robot 1 is: $$000
ENR.
PRE.
$$ROA=$$001
PRR.
GUT.Please give Result for Robot 2
PRS.|Result from Robot 2 is: $$000
ENR.
PRE.
$$ROB=$$001
STS.DUMP
WRS.$$ROA,$$ROB
GRS.$$ROA
GRS.$$ROB
STS.DUMP
MBX.!
ENR.
You will need to put some text in the two input-boxes, this text is the result from each of the two parallel robot operations.
As you can see, the WRS. will wait until both Results are available. And then present them to you.
Here is an Example that shows how you can wait for 5 Parallel Processes to end.
Click on the 5 Messageboxes and see what happens.
VAO.$$TIB=
FOR.§§LOP|1|5
' Run 5 Robots
PRR.0
MBX.!
END.
PRE.$$TIC
' Collect the Tickets separated with ","
$$TIB=$$TIB,$$TIC
NEX.
' Wait until they end
WRS.!$$TIB
ENR.
Syntax
WRS.[!][P1[,..Px]][|P2]
Parameter Explanation
! - (optional) if specified, the command will NOT react on an Result, but wait until
the specified process has ended.
P1 - (optional) Variable that contains the "Ticket-Number" which leads to the
Return code of the background job. If omitted, the last Background Operation
will be taken.
P2 - (optional) Timeout-Value. If omitted no timeout is used.
Example
'***********************************
' SMB.-Sample
'***********************************
' Send away 25 Mails
' then wait until they are sent
' and then show the results of all 25 Mails.
'
'#EXE:?pfad\
'#SPI:ForceWrite
'
' Background Mailer-Demo
' Please provide a complete MailConfig.dat
SMP.?path\MailConfig.dat
' Try with attachement also!
' SMP.attachment=?path\Send-Mail.zip
$$HND=
' Be careful or you may end up with in
' an error 421 - too many connections
' from your provider
FOR.$$CNT|1|25
GSB.Lab
NEX.
DBP.$$HND
WRS.$$HND
' Display Results
FEM.Lab_dis|$$TXT|$$HND|,
MBX.!
ENR.
'-----------------------------------------------------------
:Lab_dis
GRS.$$TXT|$$RES
' Always drop Results you do not need anymore
DRS.$$TXT
DBP. Result from $$TXT = $$RES
RET.
'-----------------------------------------------------------
:Lab
SMB.
$$HND=$$HND,$$000
RET.
'-----------------------------------------------------------
'***********************************
' PRR.-Sample
'***********************************
PRR.0|Desktop-1
PRR.0|Desktop-1
PRS.Robot 2 Result
END.
PRE.$$RET
WRS.$$RET
GRS.$$RET|$$RES
PRS.$$RES
DRS.$$RET
END.
PRE.$$RET
WRS.$$RET
GRS.$$RET|$$RES
MBX.Result: $$RES
DRS.$$RET
ENR.
Remarks
If you use Background Operations, always drop the result of the operation using DRS..
Otherwise it will be kept in Memory until the Script ends. This only applies to background operations that do post an result to the main script.
Limitations:
There is no technical limit in the number of background operations, that you can wait for with a single WRS. - Instruction.
See also:
• ! Smart Package Robot 's Parallel Robot Operations
• IRS. / NRS. - If Result available
• PRE. - Parallelrobot-Run-End
• ! Smart Package Robot 's Send-Mail