Previous Topic: $TIME()Next Topic: $WHEREFROM()


$TIMER()

This function sets one or more asynchronous timers. As each interval expires, a record is written to a stack to notify your IMOD.

Syntax

Form 1:

id = $TIMER(SET,sec,stknum,[rec],[imodid])

Form 2:

id = $TIMER(CLEAR,id)

Parameters

SET

Establishes a new timer interval without affecting existing intervals.

CLEAR

Clears an existing interval.

id

Unique ID assigned by timing facility. If you are canceling an existing interval, specify this ID.

sec

Number of seconds in the interval.

stknum

Number of the stack posted when the interval expires.

rec

1 to 256-byte argument that is placed on the stack when the interval expires. The default is TIME_EXPIRED.

imodid

IMOD that owns the stack that is being posted when the interval expires.

Usage Notes

When an interval expires, the text in rec (or TIME_EXPIRED) is written to the stack, followed by a blank and the interval ID (id) returned by the SET argument.

Return Codes

101 - 105

ARG n MISSING OR INVALID

121

TIMER IS NOT AVAILABLE

122

SYSTEM SHUTDOWN IN EFFECT

123

STORAGE EXHAUSTED

Example

/* Set two timers */
id1 = $timer('set',10,1,'INTERVAL_1')
 id2 = $timer('set',60,1,'INTERVAL_2')
.../* start other processes */
x = wait(0,1,2) /* wait on multiple events)
 if x = 1 then do
    rec = pull(1)
    parse var rec string id .
    select
        when string = 'INTERVAL_1 then call expire_1
        when string = 'INTERVAL_2 then call expire_2
        otherwise signal timer_error
        end
    end