I would like to start a timer in my common lisp application that after a certain amount of time it will call a certain method. What would be the best way to accomplish this? <
make-timer
and schedule-timer
SBCL has built-in functions for this.
SBCL supports a system-wide event scheduler implemented on top of setitimer that also works with threads but does not require a separate scheduler thread.
This examples executes a function after 2 seconds:
(schedule-timer (make-timer (lambda ()
(write-line "Hello, world")
(force-output)))
2)
Among other methods we have unschedule-timer
and list-all-timers
.
Xach Bean's timer dates from 2003. It is possible these SBCL methods are more recent.
With the Clerk library, we can run regular jobs:
(job "Say 'Hi' all the time" every 5.seconds (print "Hi"))
This will run every 5 seconds. Without "every" it would be a one-time job:
(job "Extraordinary event" in 5.days (send-mail "Don't forget X"))
where we can use any word instead of "in".
I also encountered but didn't try https://github.com/Shinmera/simple-tasks