Skip to content

Commit

Permalink
update tests and benchs for new Fut API
Browse files Browse the repository at this point in the history
  • Loading branch information
c-cube committed Nov 8, 2023
1 parent f830b55 commit 9568ea7
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 15 deletions.
2 changes: 1 addition & 1 deletion benchs/fib_rec.ml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ let rec fib ~on x : int Fut.t =
if x <= !cutoff then
Fut.spawn ~on (fun () -> fib_direct x)
else
let open Fut.Infix_local in
let open Fut.Infix in
let+ t1 = fib ~on (x - 1) and+ t2 = fib ~on (x - 2) in
t1 + t2

Expand Down
4 changes: 1 addition & 3 deletions test/effect-based/t_many.ml
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@ let run ~pool () =
0 l)
in

let futs =
List.init n_tasks (fun _ -> Fut.spawn ~on:pool task |> Fut.join ~on:pool)
in
let futs = List.init n_tasks (fun _ -> Fut.spawn ~on:pool task |> Fut.join) in

let lens = List.map Fut.wait_block_exn futs in
Printf.printf "awaited %d items (%d times)\n%!" (List.hd lens) n_tasks;
Expand Down
2 changes: 1 addition & 1 deletion test/t_chan_train.ml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ open Moonpool
(* large pool, some of our tasks below are long lived *)
let pool = Ws_pool.create ~num_threads:30 ()

open (val Fut.infix pool)
open Fut.Infix

type event =
| E_int of int
Expand Down
17 changes: 7 additions & 10 deletions test/t_tree_futs.ml
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,16 @@ let rec mk_tree ~pool n : _ tree Fut.t =
let@ _sp = Trace.with_span ~__FILE__ ~__LINE__ "mk-tree" in
if n <= 1 then
Fut.return (Leaf 1)
else
let open (val Fut.infix pool) in
let l =
Fut.spawn ~on:pool (fun () -> mk_tree ~pool (n - 1)) |> Fut.join ~on:pool
and r =
Fut.spawn ~on:pool (fun () -> mk_tree ~pool (n - 1)) |> Fut.join ~on:pool
in
else (
let l = Fut.spawn ~on:pool (fun () -> mk_tree ~pool (n - 1)) |> Fut.join
and r = Fut.spawn ~on:pool (fun () -> mk_tree ~pool (n - 1)) |> Fut.join in

Fut.return @@ Node (l, r)
)

let rec rev ~pool (t : 'a tree Fut.t) : 'a tree Fut.t =
let@ _sp = Trace.with_span ~__FILE__ ~__LINE__ "rev" in
let open (val Fut.infix pool) in
let open Fut.Infix in
t >>= function
| Leaf n -> Fut.return (Leaf n)
| Node (l, r) ->
Expand All @@ -36,7 +33,7 @@ let rec rev ~pool (t : 'a tree Fut.t) : 'a tree Fut.t =

let rec sum ~pool (t : int tree Fut.t) : int Fut.t =
let@ _sp = Trace.with_span ~__FILE__ ~__LINE__ "sum" in
let open (val Fut.infix pool) in
let open Fut.Infix in
t >>= function
| Leaf n -> Fut.return n
| Node (l, r) ->
Expand All @@ -45,7 +42,7 @@ let rec sum ~pool (t : int tree Fut.t) : int Fut.t =

let run ~pool n : (int * int) Fut.t =
let@ _sp = Trace.with_span ~__FILE__ ~__LINE__ "run" in
let open (val Fut.infix pool) in
let open Fut.Infix in
let t = Fut.return n >>= mk_tree ~pool in
let t' = rev ~pool t in
let sum_t = sum ~pool t in
Expand Down

0 comments on commit 9568ea7

Please sign in to comment.