include "timers.m"; timers := load Timers Timers->PATH; Timer: adt { timeout: chan of int; start: fn(msec: int): ref Timer; stop: fn(t: self ref Timer); }; init: fn(minms: int): int; shutdown: fn();
The module must first be initialised by calling init, which starts a process to manage the interval timers and returns its process ID. Before exit, the caller must shut the timing process down either by calling shutdown, which stops it synchronously; by using the process ID returned by init to kill it; or by killing the process group of the process that called init (since the timing processes remain in that group). Minms gives the minimum granularity of timing requests in milliseconds.
Each Timer value times a single interval. When a timer t expires, the timing process attempts, at that and each subsequent timing interval, to send on t.timeout until the expiry message is delivered or the timer is stopped.
t := Timer.start(600); alt { data := <-input => t.stop(); # process the data <-t.timeout => # request timed out }
TIMERS(2 ) | Rev: Tue Mar 31 02:42:39 GMT 2015 |