Skip to content

Commit

Permalink
add event holding function
Browse files Browse the repository at this point in the history
  • Loading branch information
Keryan-dev committed Jun 26, 2024
1 parent 4c4968d commit 9cc101b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/ocamlCanvas.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1078,6 +1078,10 @@ module V1 = struct
external key_of_int : int -> key
= "ml_canvas_key_of_int"

let held_events = ref []

let hold (e : unit React.event) = held_events := e::!held_events

end

module InternalEvent = struct
Expand Down Expand Up @@ -1184,6 +1188,7 @@ module V1 = struct
let run k =
let open InternalEvent in
let open Event in
let k () = held_events := []; k () in
let h e =
(match e with
| FrameCycle { timestamp } ->
Expand Down
5 changes: 5 additions & 0 deletions src/ocamlCanvas.mli
Original file line number Diff line number Diff line change
Expand Up @@ -1498,6 +1498,11 @@ module V1 : sig
{ul
{- {!Invalid_argument} if [i] < 0 or [i] > 255}} *)

val hold : unit React.event -> unit
(** [hold e] ensures that effectful React event [e] won't be
collected early by the GC. In particular, in the case of the
Javascript backend where a global reference might not be
enough. *)

end

Expand Down

0 comments on commit 9cc101b

Please sign in to comment.