11 System Clock
WAIT [numeric expression]
The numeric expression can range from -2147483648 through 2147483647 (about 596 hours); a negative number defaults to 0. The wait can be interrupted by pressing BREAK or a user-defined special function key (softkey or SFK).
Consider the following program extract:
2010 WAIT 8000The WAIT command with a time interval (in milliseconds) provides the specified delay. However, this approach has the following potential difficulties:
2010 Start=CLOCK 2020 WHILE CLOCK-Start%<8000 2030 END WHILENOTE: This code results in an eight second programmed delay; however, the delay is a busy wait, meaning that the program demands processor execution time for the entire period of the delay. On a multiple user configuration, another process would effectively execute at half speed during the eight seconds.
ON KEY#8:"EXIT" GOTO E REQUEST #11 PRINTER IS 11 ON INPUT #11 GOSUB P WAIT E: STOP P: A$=AREAD$(11) ... PRINT ">" WAIT 500 PRINT "<" RETURNThis program works well and may be used to get data from PORT #11 until KEY#8 is pressed. Now we are in BACKGROUND - what happens is as follows: The WAIT statement will read the next line from stdin. If there is no more line on stdin the program will be terminated at once. The only valid input is ":KEY #8" which will terminate the program. The timed DELAY in the subprogram will be ignored. The program will not work.
The solution for the above problem is the SLEEP statement. If you replace the WAIT statement with a SLEEP statement, this program will behave in background the same as in foreground.
NOTE: Don't exchange WAIT with SLEEP statement without further investigation: SLEEP will not read stdin, so it's impossible to trigger a key "press" via stdin.