File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -27,8 +27,18 @@ let should_run () = not !should_exit_
2727exception ShouldExit
2828
2929let signal_exit =
30- let do_lwt = lazy (Lwt. wakeup_later signal_exit_lwt () ) in
31- (* invariant: should_exit_ = (Lwt.state should_exit_lwt = Lwt.Return) *)
30+ let do_lwt = lazy (
31+ (* we can't use Lwt's wakeup_later because it doesn't always "later", it
32+ soemtimes behaves the same as plain wakeup *)
33+ Lwt. dont_wait
34+ (fun () ->
35+ Lwt. bind
36+ (Lwt. pause () )
37+ (fun () -> Lwt. wakeup signal_exit_lwt () ; Lwt. return_unit))
38+ (fun exc -> log#error " signal exit: error at wakeup: %s" (Printexc. to_string exc))
39+ )
40+ in
41+ (* nearly-invariant: should_exit_ = (Lwt.state should_exit_lwt = Lwt.Return) *)
3242 fun () -> should_exit_ := true ; Lazy. force do_lwt
3343
3444(* * @raise ShouldExit if [should_exit] condition is set, otherwise do nothing *)
You can’t perform that action at this time.
0 commit comments