Common Lisp Timer

前端 未结 5 1812
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-02-20 03:08

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? <

相关标签:
5条回答
  • 2021-02-20 03:42

    It's SBCL-dependent, but you might want to try out Zach Beane's TIMER.

    0 讨论(0)
  • 2021-02-20 03:47

    Would something as simple as SLEEP work?

    0 讨论(0)
  • 2021-02-20 03:47

    http://www.cliki.net/TIMER implements relative time based scheduling, which i THINK is what you mean

    0 讨论(0)
  • 2021-02-20 03:50

    With SBCL: 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 Clerk, "a cron-like scheduler with a sane DSL"

    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".

    See also

    I also encountered but didn't try https://github.com/Shinmera/simple-tasks

    0 讨论(0)
  • 2021-02-20 03:53

    You could use CL's SLEEP, unless you need more precise timing (since SLEEP is permitted to use approximate timing.)

    In LispWorks, if more precise timing is needed, one could use LispWorks' timer scheduling interface.

    Note that, same as Zach Beane's TIMER, this is not implementation-agnostic.

    0 讨论(0)
提交回复
热议问题