tur/timer
stdlib/timer.tur
Timer API backed by a min-heap timer wheel.
Since: Phase T24
defn
timer-set
(timer-set [ms :int callback :ptr<void> arg :ptr<void>] :int)
schedule a one-shot callback after a delay.
Parameters
| ms | delay in milliseconds before the callback fires (:int). | |
| callback | a :ptr<void> to the function to invoke; signature void(*)(void*). | |
| arg | opaque :ptr<void> passed to callback when it fires. |
Returns
A timer ID (int) that can be passed to timer-cancel to abort the timer before it fires.
Example
(timer-set 500 my-cb my-arg) ; => 3 (fires in 500 ms)
Since: Phase T24
defn
timer-cancel
(timer-cancel [id :int] :nil)
cancel a previously scheduled timer.
Parameters
| id | the timer ID returned by timer-set. |
Example
(timer-cancel 3) ; cancel timer with ID 3
Since: Phase T24
defn
timer-sleep
(timer-sleep [ms :int] :nil)
park the current fiber for a given number of milliseconds.
Parameters
| ms | number of milliseconds to sleep (:int); no-op if <= 0. |
Example
(timer-sleep 1000) ; pause the current fiber for 1 second
Since: Phase T24