From 4f262d6540281487f79870aff589ca92f5d2f6c6 Mon Sep 17 00:00:00 2001 From: Sébastien Dailly Date: Wed, 16 Dec 2020 14:39:42 +0100 Subject: Initial commit --- events/dune | 7 +++++++ events/timer.ml | 24 ++++++++++++++++++++++++ events/timer.mli | 7 +++++++ 3 files changed, 38 insertions(+) create mode 100755 events/dune create mode 100755 events/timer.ml create mode 100755 events/timer.mli (limited to 'events') 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 -- cgit v1.2.3