Skip to content
abinition edited this page Oct 21, 2014 · 6 revisions

#alarm

###Set an alarm to trigger after a specified duration.

Syntax

status = alarm seconds ;

Arguments

  1. int seconds

The number of seconds before the alarm is triggered.

Return Value

boolean status
  • 1 : The alarm was set.

The STATUS variable is set to $ACKNOWLEDGE

  • 0 : Invalid alarm seconds, not between 0 and 86400 seconds (1 day).

The STATUS variable is set to %BOUNDS

Warnings

  • %BOUNDS : Invalid alarm seconds, not between 0 and 86400 seconds (1 day).

Exceptions

  • %ARGUMENT: Invalid arguments. Usage: status = alarm seconds ;

Description

When an alarm is triggered, the STATUS variable is set to "%ALARM". Depending on the state of the program and whether an alarm handler was specified with the on_alarm statement, the program will take the additional actions as follows:

State of HypersScript prior to alarm No handler, STATUS set to %ALARM Handler sets STATUS to TRUE condition(*) Handler sets STATUS to FALSE condition(*)
EXECUTE HyperScript terminates. HyperScript continues to execute. HyperScript terminates.
IDLE HyperScript terminates. HyperScript continues to idle. HyperScript aborts idle state, value of idle() function equals STATUS.
QUERY HyperScript terminates. HyperScript continues to wait for reply. HyperScript aborts query, value of query*() function equals STATUS.

(*) The handler must set the STATUS variable just before it exits. A handler can set a TRUE or FALSE condition in the STATUS variable such as in the following examples:

on_alarm STATUS = "$ACK" ;
H() { return "%BAD" ; } ;
on_alarm return H() ;
on_alarm continue ;  //STATUS;is $ACK
on_alarm ; /* STATUS will be "%ALARM" */
alarm 2 ; stat = idle() ; puts stat ;

Examples

on_alarm {
  puts { "In handler, STATUS = ",STATUS } ;
  /* Return a FALSE status */
  return "%ALARM" ;
} ;
/* Alarm in 2 seconds */
alarm ( 2 ) ;

/* Enter IDLE state and wait for the alarm */
stat = idle () ; puts { "Resuming execution, stat = ",stat } ;

Related Links

on_alarm

Clone this wiki locally