Skip to content

Commit

Permalink
fix: logger app blocks until ready
Browse files Browse the repository at this point in the history
  • Loading branch information
leostera committed Jul 16, 2024
1 parent c71ef46 commit 14abf81
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
1 change: 1 addition & 0 deletions riot/lib/logger/logger.ml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module Log = Riot_runtime.Log
open Global

type opts = { print_source : bool; print_time : bool; color_output : bool }
type config = { opts : opts; started_by : Riot_runtime.Core.Pid.t }

type ('a, 'b) logger_format =
(('a, Format.formatter, unit, 'b) format4 -> 'a) -> 'b
Expand Down
16 changes: 13 additions & 3 deletions riot/lib/logger_app.ml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ open Logger.Make (struct
let namespace = [ "riot"; "logger" ]
end)

type Message.t += Logger_ready

module Formatter = struct
type Message.t += Log of log

Expand Down Expand Up @@ -47,7 +49,8 @@ module Formatter = struct
let pid =
spawn_link (fun () ->
Process.flag (Priority High);
formatter_loop config)
send config.started_by Logger_ready;
formatter_loop config.opts)
in
set_on_log (fun log -> send pid (Log log));
Ok pid
Expand All @@ -59,5 +62,12 @@ let default_opts =
{ print_time = true; print_source = false; color_output = true }

let start () =
let child_specs = [ Formatter.child_spec default_opts ] in
Supervisor.start_link ~child_specs ()
let this = self () in
let config = { opts = default_opts; started_by = this } in
let child_specs = [ Formatter.child_spec config ] in
let result = Supervisor.start_link ~child_specs () in
let `ready =
let selector msg = if msg = Logger_ready then `select `ready else `skip in
receive ~selector ()
in
result

0 comments on commit 14abf81

Please sign in to comment.