Skip to content

Commit c41c90e

Browse files
committed
Lwt_util: fix runaway promise in ensure_order
1 parent c46ad89 commit c41c90e

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

lwt_util.ml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,11 @@ let timely_loop' ?(immediate=false) period f =
3131
(* run f every period seconds; run immediately if immediate is true; stop when wait thread terminates *)
3232
let timely_loop ?immediate ?(wait=Daemon.wait_exit ()) period f = Lwt.pick [ wait; timely_loop' ?immediate period f; ]
3333

34-
(* cancel t1 when t2 terminates *)
35-
let ensure_order t1 t2 = (t2) [%finally Lwt.wrap1 Lwt.cancel t1; ]
34+
(* cancel t1 when t2 terminates; join so that cancelling the resulting promise cancels both t1 and t2 *)
35+
let ensure_order t1 t2 =
36+
let ignore t = let%lwt _ = t in Lwt.return_unit in
37+
let%lwt () = Lwt.join [ ignore t1; (ignore t2) [%finally Lwt.wrap1 Lwt.cancel t1; ]; ] in
38+
t2
3639

3740
(* wait for t to terminate, suppress any exception, and call cleanup () afterwards *)
3841
let suppress_exn name cleanup t =

0 commit comments

Comments
 (0)