Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions daemon.ml
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,18 @@ let should_run () = not !should_exit_
exception ShouldExit

let signal_exit =
let do_lwt = lazy (Lwt.wakeup_later signal_exit_lwt ()) in
(* invariant: should_exit_ = (Lwt.state should_exit_lwt = Lwt.Return) *)
let do_lwt = lazy (
(* we can't use Lwt's wakeup_later because it doesn't always "later", it
soemtimes behaves the same as plain wakeup *)
Lwt.dont_wait
(fun () ->
Lwt.bind
(Lwt.pause ())
(fun () -> Lwt.wakeup signal_exit_lwt (); Lwt.return_unit))
(fun exc -> log#error "signal exit: error at wakeup: %s" (Printexc.to_string exc))
)
in
(* nearly-invariant: should_exit_ = (Lwt.state should_exit_lwt = Lwt.Return) *)
fun () -> should_exit_ := true; Lazy.force do_lwt

(** @raise ShouldExit if [should_exit] condition is set, otherwise do nothing *)
Expand Down