Skip to content

Commit

Permalink
Cookbook : fix in Lwt (type mismatch with iter_s/iter_p functions) (#…
Browse files Browse the repository at this point in the history
…2127)

* Cookbook : fix in Lwt

* Update 00-lwt.ml

---------

Co-authored-by: Frédéric LOYER <[email protected]>
  • Loading branch information
2 people authored and Cuihtlauac ALVARADO committed Apr 25, 2024
1 parent fa77762 commit 8610b97
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions data/cookbook/concurrency/lwt/00-lwt.ml
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,18 @@ let task n =
let (_result1, _result2) =
Lwt_main.run @@ Lwt.both (task 1) (task 2)

(* When having a promise function which should be scheduled multiple times with different values, `iter_p`, `iter_s`, `map_p`, `map_s` schedule one promise per item from a given list. The `_s` versions schedule the promises sequentialy, and `_p` in parallel. `iter_*` return `()` while `map_*`return the list of results. *)
(* When having a promise function which should be scheduled multiple times with different values, `iter_p`, `iter_s`, `map_p`, `map_s` schedule one promise per item from a given list. The `_s` versions schedule the promises sequentialy, and `_p` in parallel. `iter_*` return `()` (and expect tasks which return a unit Lwt) while `map_*`return the list of results. *)
let _result_list =
Lwt_main.run @@ Lwt_list.map_p task [1; 2; 3]
let _result_list =
Lwt_main.run @@ Lwt_list.map_s task [1; 2; 3]
Lwt_main.run @@ Lwt_list.map_s task [1; 2; 3]
let task' n =
let* _result = task n in
Lwt return ()
let () =
Lwt_main.run @@ Lwt_list.iter_p task [1; 2; 3]
Lwt_main.run @@ Lwt_list.iter_p task' [1; 2; 3]
let () =
Lwt_main.run @@ Lwt_list.iter_s task [1; 2; 3]
Lwt_main.run @@ Lwt_list.iter_s task' [1; 2; 3]

(* `sleep seconds` pauses for then given seconds number. *)
let () =
Expand Down

0 comments on commit 8610b97

Please sign in to comment.