(set-timer n)
starts an internal timer that calls the timer interrupt handler after n
ticks. A tick is a rough measure of the amount of work being done, not a measure of clock time. If scheme is just sitting at the REPL prompt, no work is being done and the timer handler will not be called.
This is probably not the functionality you're looking for. If you want a clock-based timer, you will need to build it yourself, possibly in terms of set-timer
.
The following code demonstrates use of set-timer
. But again, it's not clock time.
$ scheme
Chez Scheme Version 9.5.8
Copyright 1984-2022 Cisco Systems, Inc.
> (define (start-periodic-timer n f)
(timer-interrupt-handler (lambda ()
(f)
(set-timer n)))
(set-timer n))
> (start-periodic-timer 3000 (lambda () (printf "timer!")))
0
> (do ([i 0 (+ i 1)]) ((= i 2000) (newline)) (printf "."))
timer!timer!timer!timer!.....................................................
.............................................................................
.............................................................................
.............................................................................
.............................................................................
.............................................................................
.............................................................................
.............................................................................
.............................................................................
.............................................................................
.............................................................................
....................................timer!...................................
.............................................................................
.............................................................................
.............................................................................
.............................................................................
.............................................................................
.............................................................................
.............................................................................
.............................................................................
.............................................................................
.............................................................................
.............................................................................
.............................................................................
............................timer!...........................................
.............................................................................
..................................