You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It's possible for multiple promises in ps to become resolved simultaneously. This happens most often when some promises ps are already resolved at the time Lwt.pick is called.
In that case, if at least one of the promises is rejected, the result promise p is rejected with the same exception as one such promise, chosen arbitrarily. If all promises are fulfilled, p is fulfilled with the value of one of the promises, also chosen arbitrarily.
let rec loop (ok, err) = function
| n when n <= 0 -> Lwt_io.printlf "ok %d err %d" ok err
| n ->
let%lwt res =
let exception Err of (int * int) in
try%lwt Lwt.pick [ Lwt.return (succ ok, err); Lwt.fail (Err (ok, succ err)); ] with Err x -> Lwt.return x
in
loop res (pred n)
in
loop (0, 0) 10;;
Your diagnostic is correct. In fact, when multiple promises are already resolved, pick simply takes a random one of them. It doesn't special case whether some of the already resolved promises are rejected or not.
Activity
raphael-proust commentedon May 25, 2021
Hello,
Your diagnostic is correct. In fact, when multiple promises are already resolved,
picksimply takes a random one of them. It doesn't special case whether some of the already resolved promises are rejected or not.I'll prepare an MR to fix that.
Lwt.pick and Lwt.choose pick preferentially failed promises
Lwt.pick and Lwt.choose pick preferentially failed promises
Lwt.pick and Lwt.choose pick preferentially failed promises
Lwt.pick and Lwt.choose pick preferentially failed promises