SLEEP, RQM

Top  Previous  Next

 

The SLEEP statement causes the program in which it is executed to pause for a given number of seconds or until a specific time. The synonym RQM may be used in place of SLEEP.

 

 

Format

 

SLEEP {time}

 

where

 

timedetermines the time for which the program is to sleep. If omitted, time defaults to one.

 

 

The SLEEP statement operates in one of two ways depending on the format of time.

 

If time is a number, it is rounded to an integer value and the program sleeps for that number of seconds. If time is negative or zero, the program continues without sleeping.

 

If time is not a number, an attempt is made to convert it to a time of day using any of the formats accepted by the ICONV() function MT conversion. If successful, the program sleeps until this time. The SLEEP statement used in this way cannot sleep across midnight. If the time of day specified by time has already passed or if time cannot be converted to a time of day, the program continues without sleeping.

 

In all cases, if there is more than one process running, the SLEEP statement causes a process switch to occur. It can therefore be used to relinquish the remainder of the timeslice of the current process if waiting for some event to occur in another process, such as release of a lock.

 

If the break key is used to interrupt a program which is sleeping, selection of the G option will continue to sleep to the specified time. The Q option will abort the program immediately.

 

 

Examples

 

SLEEP "10:30PM"

 

This statement causes the program to sleep until half past ten at night unless it is already later than that time.

 

 

SLEEP 10

 

This statement causes the program to pause for 10 seconds

 

 

DISPLAY "Time to continue"

INPUT T

DELAY = ICONV(T, "MT") - TIME()

IF DELAY < 0 THEN DELAY += 86400

SLEEP DELAY

 

This program fragment prompts for and reads a time of day from the keyboard. It then converts this to a number of seconds from the current time and sleeps until this time. This technique, with the conditional statement handling times earlier than the current time allows the program to sleep across midnight.

 

 

See also:

NAP