Object » Delay
Delay implements a facility to pause a process for some amount of time. The simplest usage is like this:
(Delay forSeconds: 5) wait.
An instance of Delay responds to the message wait by suspending the caller's process for a certain amount of time. The duration of the pause is specified when the Delay is created with the message forMilliseconds: or forSeconds:. A Delay can be used again when the current wait has finished. For example, a clock process might repeatedly wait on a one-second Delay.
The maximum delay is (SmallInteger maxVal // 2) milliseconds, or about six days. A delay in progress when an image snapshot is saved is resumed when the snapshot is re-started. Delays work across millisecond clock roll-overs.
The following class variables are used to manage all currently active delays:
AccessProtect - Semaphore
This semaphore ensures exclusive access to the class variables.
ActiveDelay - Delay
A reference to the active delay if there is one, otherwise nil. In a
collection of several delays, the active delay is the one that expires
first.
ActiveDelayStartTime - Integer
The time in milliseconds when the active delay expires.
SuspendedDelays - SortedCollection
A collection of all delays that wait expiration. The active delay is not
an element of this collections. The suspended delays are sorted according
to their expiration times; a delay that follows SuspendedDelays first
cannot expire earlier then the delay at SuspendedDelays first.
TimingSemaphore - Semaphore
This semaphore is signalled from a primitive when the millisecond clock reaches
a previously registered value. Class method primSignal:atMilliseconds:
is used to express interest in a signal at a given future time.
delayDuration - SmallInteger
The duration of the delay in milliseconds
resumptionTime - SmallInteger
The system time in milliseconds at which the suspended process will resume. The value
is only relevant if a process is currently waiting on delaySemaphore
delaySemaphore - Semaphore
This semaphore is used to queue a process that is waiting for expiration of the
delay time.
beWaitedOn - Boolean
true if the process is currently registered in the queue of delaySemaphore,
otherwise false.
Note that it is not allowed to specify a delay with a negative amount of time. An error notification is shown when you try to create a Delay with a negative amount of time. When you have to delay a process for a computed amount of time, you should always write something like this:
Delay forMilliseconds: (computedValue max: 0).