Petrichor.Timer#
Petrichor.Timer provides cancellable wall-clock timers built on Petrichor.Task.
Loading#
Handles#
Each timer returns a handle with:
| Method | Description |
|---|---|
handle:cancel() | Stop future callbacks. The current callback may still finish. |
handle:is_cancelled() | True if cancel() was called. |
API#
Timer.after(seconds, fn) -> handle#
Call fn(handle) once after seconds.
Timer.every(seconds, fn) -> handle#
Call fn(handle) every seconds until cancelled.
Timer.after_then_every(delay, interval, fn) -> handle#
Wait delay seconds, call fn once, then call fn every interval seconds until cancelled.
Example#
import * as Timer from "Petrichor.Timer"
import * as Log from "Petrichor.Log"
declare function mod(name: string): any
const MyMod = mod("timer-demo")
MyMod.init = function () {
this._pulse = Timer.every(1.0, () => {
Log.info("timer-demo", "pulse")
})
}
MyMod.shutdown = function () {
this._pulse.cancel()
}
export = MyMod