diff options
Diffstat (limited to 'events')
-rwxr-xr-x | events/dune | 7 | ||||
-rwxr-xr-x | events/timer.ml | 24 | ||||
-rwxr-xr-x | events/timer.mli | 7 |
3 files changed, 38 insertions, 0 deletions
diff --git a/events/dune b/events/dune new file mode 100755 index 0000000..68e2dd2 --- /dev/null +++ b/events/dune @@ -0,0 +1,7 @@ +(library + (name events) + (libraries + brr + brr.note + ) +) diff --git a/events/timer.ml b/events/timer.ml new file mode 100755 index 0000000..def9a81 --- /dev/null +++ b/events/timer.ml @@ -0,0 +1,24 @@ +type t = Brr.G.timer_id ref * unit Note.E.send + +let create + : unit -> (t * unit Note.E.t) + = fun () -> + let event, send = Note.E.create () in + (ref (-1), send), event + +let stop + : t -> unit + = fun (id, _) -> + Brr.G.stop_timer !id + +let start + : t -> float -> unit + = fun (id, send) d -> + + Brr.G.stop_timer !id; + let timer_id = Brr.G.set_interval + ~ms:(int_of_float @@ d *. 1000.) + (fun () -> send ()) in + ignore @@ Brr.G.set_timeout ~ms:0 send; + id:= timer_id; + diff --git a/events/timer.mli b/events/timer.mli new file mode 100755 index 0000000..4bf8a9b --- /dev/null +++ b/events/timer.mli @@ -0,0 +1,7 @@ +type t + +val create : unit -> t * unit Note.E.t + +val start: t -> float -> unit + +val stop: t -> unit |