Skip to content
Snippets Groups Projects
Commit 41342b9b authored by Loïc Correnson's avatar Loïc Correnson Committed by Allan Blanchard
Browse files

[server] on-demand signal registry

parent 903c9cda
No related branches found
No related tags found
No related merge requests found
...@@ -22,23 +22,25 @@ ...@@ -22,23 +22,25 @@
open Data open Data
(* -------------------------------------------------------------------------- *)
(* --- Hooks --- *)
(* -------------------------------------------------------------------------- *)
type 'a callback = ('a -> unit) -> unit type 'a callback = ('a -> unit) -> unit
let install signal hook = function let install_hook signal hook add_hook =
| None -> () let once = ref true in
| Some add_hook -> let install ok =
let once = ref true in if ok && !once then
let install ok = begin
if ok && !once then once := false ;
begin add_hook hook ;
once := false ; Request.emit signal ;
add_hook hook ; end
Request.emit signal ; in Request.on_signal signal install
end
in Request.on_signal signal install let register_hook signal add_hook =
install_hook signal (fun () -> Request.emit signal) add_hook
let install_emit signal add_hook =
install signal (fun _ -> Request.emit signal) add_hook
(* -------------------------------------------------------------------------- *) (* -------------------------------------------------------------------------- *)
(* --- Values --- *) (* --- Values --- *)
...@@ -60,7 +62,7 @@ let register_value (type a) ~package ~name ~descr ...@@ -60,7 +62,7 @@ let register_value (type a) ~package ~name ~descr
~package ~name:(Package.Derived.getter id).name ~package ~name:(Package.Derived.getter id).name
~descr:(plain "Getter for state" @ href) ~descr:(plain "Getter for state" @ href)
~kind:`GET ~input:(module Junit) ~output get in ~kind:`GET ~input:(module Junit) ~output get in
install_emit signal add_hook ; Option.iter (register_hook signal) add_hook ;
signal signal
(* -------------------------------------------------------------------------- *) (* -------------------------------------------------------------------------- *)
...@@ -86,7 +88,7 @@ let register_state (type a) ~package ~name ~descr ...@@ -86,7 +88,7 @@ let register_state (type a) ~package ~name ~descr
~package ~name:(Package.Derived.setter id).name ~package ~name:(Package.Derived.setter id).name
~descr:(plain "Setter for state" @ href) ~descr:(plain "Setter for state" @ href)
~kind:`SET ~input:(module D) ~output:(module Junit) set in ~kind:`SET ~input:(module D) ~output:(module Junit) set in
install_emit signal add_hook ; Option.iter (register_hook signal) add_hook ;
signal signal
(* -------------------------------------------------------------------------- *) (* -------------------------------------------------------------------------- *)
...@@ -382,9 +384,9 @@ let register_array ~package ~name ~descr ~key ...@@ -382,9 +384,9 @@ let register_array ~package ~name ~descr ~key
~kind:`GET ~input:(module Junit) ~output:(module Junit) ~kind:`GET ~input:(module Junit) ~output:(module Junit)
(fun () -> reload array) ; (fun () -> reload array) ;
synchronize array ; synchronize array ;
install signal (update array) add_update_hook ; Option.iter (install_hook signal (update array)) add_update_hook ;
install signal (remove array) add_remove_hook ; Option.iter (install_hook signal (remove array)) add_remove_hook ;
install signal (fun () -> reload array) add_reload_hook ; Option.iter (install_hook signal (fun () -> reload array)) add_reload_hook ;
array array
(* -------------------------------------------------------------------------- *) (* -------------------------------------------------------------------------- *)
...@@ -26,6 +26,10 @@ open Package ...@@ -26,6 +26,10 @@ open Package
type 'a callback = ('a -> unit) -> unit type 'a callback = ('a -> unit) -> unit
(** Connect a hook registry to a signal. As soon as the signal is being
traced, a hook to emit the signal is registered. *)
val register_hook : Request.signal -> 'a callback -> unit
(** Register a (projectified) value and generates the associated signal and (** Register a (projectified) value and generates the associated signal and
request: request:
- Signal [<name>.sig] is emitted on value updates; - Signal [<name>.sig] is emitted on value updates;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment