%ALARM

%ALARM


%ACCEPT Index Level %BIND
Syntax variable = %ALARM( number )
Category BASIC
Type C Function
Description instructs the alarm clock of the calling process to send the signal "SIGALRM" to the calling process after the number of seconds specified in "number".

The default alarm handler is null (i.e.: it just interrupts the process). If "number" is 0, any previously made alarm request is canceled. If a user-written built-in function changes the alarm signal handler, it remains in effect, even if the FlashBASIC program terminates, until the process is disconnected from the virtual machine.

The alarm signal handler can be assigned to any Pick command using the (TCL) "trap" command.

To differentiate between an alarm and another interrupt, the FlashBASIC program may have to check the time. See the example below.
Options
See Also c function trap CFUNCTION useralarm
Example * Set a timer
alarmend=time()+3
%alarm( 3 )
* Read from device
n=%read(fd, buffer, BUFSIZE)
if n<0 and system(0)=EINTR then
 * Read was interrupted
 if time() >= alarmend then
   * Was the timer
   stop "time out"
 end else
   * Not the timer. Disarm it
   %alarm(0)
 end
end else
 * Read completed. Cancel timer
 %alarm( 0 )
end
Warnings
Compatibility D3/Unix
%ACCEPT Index Level %BIND