Topic complex |
System functions |
Function |
timeout() |
Short |
(Linux only) Quits execution of a procedure after a timeout passed |
Syntax |
Timeout(seconds : INTEGER) : INTEGER |
Parameter |
seconds : Number of seconds until execution abort or 0 to cancel a previously set timeout |
Return |
|
See also: |
|
Description |
This function calls the linux function Alarm and passes the given parameter to it.
The linux kernel then sends a SIGALRM signal to the process calling after a given number of seconds have passed.
Tdbengine processes this signal by immediately leaving the currently processed procedure by executing RETURN 0 (or RETURN "" for STRING functions).
In case that, before the signal was sent, the function Timeout() has been called with the parameter 0, no signal will be send at all.
This allows a easy but effective way to code timeouts.
|
Example 1: Timeout + ReadLn from console
The user has 10 seconds to enter his account ID.
PROCEDURE Input : INTEGER
VAR id : STRING
Timeout(10)
writeln(0,'Your account id: ')
id:=readln(0)
TimeOut(0)
RETURN 1
ENDPROC
PROCEDURE Main
cgiclosebuffer
IF Input THEN
writeln(0,'Your input will be processed now...')
ELSE
writeln(0,'Cancel forced by timeout')
END
ENDPROC
|
Write a comment:
|