A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/ocsigen/lwt/issues/856 below:

Semantics of Lwt.pick / choose · Issue #856 · ocsigen/lwt · GitHub

The documentation for Lwt.pick says:

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.

However, the first sentence in the second paragraph isn't true, judging by the code
https://github.com/ocsigen/lwt/blob/master/src/core/lwt.ml#L2753-L2755

a simple test confirms this:

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;;

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4