package miaou-core
Install
dune-project
Dependency
Authors
Maintainers
Sources
md5=60a3b9f181f24572a06a9492532bfdda
sha512=fcc35a275066be2900e6201782faf47503076fa4640f08cf78067835a6f447b74613009e55b2ac799adb7ca46f1bffa261fc5971753f2cc3c6bef327511c7ef6
doc/miaou-core.interfaces/Miaou_interfaces/Timer/index.html
Module Miaou_interfaces.TimerSource
Page-scoped timer callbacks for periodic and one-shot state updates.
Timers are registered by pages/widgets and checked by the driver on every tick. When a timer's deadline is reached, it is marked as "fired" for the current tick. Pages consume fired timers in their refresh function (or service_cycle) by calling drain_fired.
All timers are automatically cleared on page navigation via clear_all, giving page-scoped lifecycle with zero page cooperation.
Usage in pages:
(* In init or on_key: register a 5-second periodic refresh *)
let timer = Timer.require () in
timer.set_interval ~id:"poll" 5.0 ;
(* In refresh: check which timers fired *)
let fired = timer.drain_fired () in
if List.mem "poll" fired then
(* re-fetch data *)Usage in drivers:
let timer_state = Timer.create_state () in
Timer.register timer_state ;
(* At the top of every tick: *)
Timer.tick timer_state ;
(* On page switch: *)
Timer.clear_all timer_state ;Timer kinds
Whether a timer repeats or fires once.
Mutable driver-side state
Opaque driver-side state. Drivers create one, register it, and call tick on each loop iteration.
Read-only capability view
type t = {set_interval : id:string -> float -> unit;(*
*)set_interval ~id interval_sregisters (or replaces) a repeating timer with the givenid. It will first fire afterinterval_sseconds, then repeat.set_timeout : id:string -> float -> unit;(*
*)set_timeout ~id delay_sregisters a one-shot timer. It fires once afterdelay_sseconds and is then automatically removed.clear : string -> unit;(*
*)clear idremoves the timer with the givenid. No-op if no such timer exists.drain_fired : unit -> string list;(*Return the list of timer IDs that fired since the last call to
*)drain_fired(or since the lasttick), and reset the fired set. Typically called inrefresh.active_ids : unit -> string list;(*Return the IDs of all currently registered timers.
*)
}The interface exposed to pages and widgets via the capability registry.
Capability access
Driver-side API
Create a new empty timer state. Uses Clock.require () to obtain the current time, so the Clock capability must be registered first.
Advance timers. Call this at the top of every tick iteration, after Clock.tick. Checks all registered timers against the current clock time, marks due ones as fired, reschedules intervals, and removes expired timeouts.