Timer functions for delayed and periodic operations.
Timers are implemented as processes:
All timer functions return a Timer record that can be passed to cancel.
Timer functions for delayed and periodic operations. Timers are implemented as processes: - One-shot timers: unlinked process that sleeps then executes - Interval timers: linked process that loops, stopping when caller dies All timer functions return a Timer record that can be passed to cancel.
(cancel timer)Cancel a timer. Returns true if timer process existed, false otherwise.
Cancel a timer. Returns true if timer process existed, false otherwise.
(start-timer
{:keys [after-ms every-ms link catch-all] :or {after-ms 0} :as opts}
f
&
args)Create and start a timer. Returns a Timer record.
Options:
Examples: (start-timer {:after-ms 1000} f) ; one-shot after 1s (start-timer {:after-ms 1000 :every-ms 1000} f) ; every 1s (start-timer {:after-ms 0 :every-ms 1000} f) ; immediately, then every 1s (start-timer {:after-ms 1000 :link true} f x y) ; one-shot, linked (start-timer {:every-ms 1000 :catch-all true} f) ; interval, survives exceptions
Create and start a timer. Returns a Timer record.
Options:
- :after-ms - ms before first fire (default: 0)
- :every-ms - ms between fires (nil = one-shot)
- :link - link to caller (default: true if :every-ms, false otherwise)
- :catch-all - catch exceptions in f and continue (default: false)
Examples:
(start-timer {:after-ms 1000} f) ; one-shot after 1s
(start-timer {:after-ms 1000 :every-ms 1000} f) ; every 1s
(start-timer {:after-ms 0 :every-ms 1000} f) ; immediately, then every 1s
(start-timer {:after-ms 1000 :link true} f x y) ; one-shot, linked
(start-timer {:every-ms 1000 :catch-all true} f) ; interval, survives exceptions(tc n unit)Time constant - convert time unit to milliseconds. (tc 5 :seconds) => 5000 (tc 2 :minutes) => 120000
Time constant - convert time unit to milliseconds. (tc 5 :seconds) => 5000 (tc 2 :minutes) => 120000
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |