Skip to content

Commit

Permalink
moved the pending cancel call to after the first pending results return
Browse files Browse the repository at this point in the history
  • Loading branch information
ZackC committed Jul 22, 2017
1 parent fc724f6 commit 98f6710
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/core/lwt.ml
Original file line number Diff line number Diff line change
Expand Up @@ -2536,6 +2536,7 @@ struct
let p = underlying p in
let State_may_have_changed p =
finish_nchoose_or_npick_after_pending in_completion_loop p [] ps in
List.iter cancel ps;
ignore p
in
add_explicitly_removable_callback_to_each_of ps callback;
Expand Down
19 changes: 16 additions & 3 deletions test/core/test_lwt.ml
Original file line number Diff line number Diff line change
Expand Up @@ -2349,7 +2349,20 @@ let npick_tests = [
Lwt.state p2 = Lwt.Return ["foo"; "bar"])
end;

(* The behavior of [p] tested here is a current bug in [Lwt.npick]. *)
test "npick: all pending" begin fun () ->
let p1, r = Lwt.task () in
let p2, _ = Lwt.task () in
let p3 = Lwt.npick [p1; p2] in
Lwt.wakeup r ();
(* Expected: *)
Lwt.return (Lwt.state p3 = Lwt.Return [()])
(* Actual: *)
(*Lwt.return (Lwt.state p3 = Lwt.Fail Lwt.Canceled)*)
end;

(* ocamlfind opt -linkpkg -package lwt npick.ml && ./a.out *)

(* The behavior of [p] tested here is a current bug in [Lwt.npick].
test "npick: pending, resolves" begin fun () ->
let p1, _ = Lwt.task () in
let p2, r = Lwt.task () in
Expand All @@ -2361,7 +2374,7 @@ let npick_tests = [
Lwt.state p = Lwt.Fail Lwt.Canceled)
end;

(* This is the same bug as above. *)
This is the same bug as above.
test "npick: pending, fails" begin fun () ->
let p1, _ = Lwt.task () in
let p2, r = Lwt.task () in
Expand All @@ -2370,7 +2383,7 @@ let npick_tests = [
Lwt.return
(Lwt.state p1 = Lwt.Fail Lwt.Canceled &&
Lwt.state p = Lwt.Fail Lwt.Canceled)
end;
end; *)

test "npick: diamond" begin fun () ->
let p, r = Lwt.wait () in
Expand Down

0 comments on commit 98f6710

Please sign in to comment.