Skip to content

Commit

Permalink
fix "double asking to reload" bugs in an unsatisfying one
Browse files Browse the repository at this point in the history
I don't know why it was logged twice, but using the tricks of "Asking browserS
to reload" I can make it log only once.

Signed-off-by: Paul-Elliot <[email protected]>
  • Loading branch information
panglesd committed Feb 16, 2024
1 parent 762a091 commit 7d22bf4
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions compiler/src/bin/native/serve.ml
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,11 @@ let do_serve input f =
@@ Dream.router
[
Dream.get "/" (fun _ ->
Dream.log "Browser reloaded";
Dream.log "A browser reloaded";
Dream.html !content);
Dream.get "/_livereload" (fun _ ->
Dream.websocket (fun socket ->
let* () = !waiter in
Dream.log "Asking browser to reload";
Dream.close_websocket socket));
]
in
Expand All @@ -56,10 +55,12 @@ let do_serve input f =
content := new_content;
let* _event = Lwt_inotify.read inotify in
Logs.app (fun m -> m "Recompiling");
Lwt.wakeup_later !resolver ();
let old_resolver = !resolver in
let nwaiter, nresolver = Lwt.wait () in
waiter := nwaiter;
resolver := nresolver;
Dream.log "Asking browsers to reload";
Lwt.wakeup_later old_resolver ();
loop ()
in
loop ()
Expand Down

0 comments on commit 7d22bf4

Please sign in to comment.