mirror of
https://github.com/c-cube/moonpool.git
synced 2025-12-06 03:05:30 -05:00
add Fut.for_array to easily iterate on an array in parallel
This commit is contained in:
parent
826d1f15c8
commit
debdc8fc31
2 changed files with 10 additions and 0 deletions
|
|
@ -303,6 +303,9 @@ let for_ ~on n f : unit t =
|
|||
~map:(fun _f () -> ())
|
||||
()
|
||||
|
||||
let for_array ~on arr f : unit t =
|
||||
for_ ~on (Array.length arr) (fun i -> f i arr.(i))
|
||||
|
||||
(* ### blocking ### *)
|
||||
|
||||
let wait_block (self : 'a t) : 'a or_error =
|
||||
|
|
|
|||
|
|
@ -130,6 +130,13 @@ val for_ : on:Pool.t -> int -> (int -> unit) -> unit t
|
|||
a future that resolves when all the tasks have resolved, or fails
|
||||
as soon as one task has failed. *)
|
||||
|
||||
val for_array : on:Pool.t -> 'a array -> (int -> 'a -> unit) -> unit t
|
||||
(** [for_array ~on arr f] runs [f 0 arr.(0)], …, [f (n-1) arr.(n-1)] in
|
||||
the pool (where [n = Array.length arr]), and returns a future
|
||||
that resolves when all the tasks are done,
|
||||
or fails if any of them fails.
|
||||
@since 0.2 *)
|
||||
|
||||
(** {2 Blocking} *)
|
||||
|
||||
val wait_block : 'a t -> 'a or_error
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue