Compare commits

..

2 Commits

Author SHA1 Message Date
Thomas Leonard
4856fc430d
Merge pull request #665 from talex5/all-shared
Fiber.all: use the parent fiber
2024-01-04 08:57:54 +00:00
Thomas Leonard
2aaea3f48e Fiber.all: use the parent fiber
Previously, it created one fiber for each job and then the parent
fiber just waited. It's a little more efficient to have the parent
fiber run the last job itself, and also reduces clutter in the traces.

This also affects `Fiber.both`, which uses `all` internally.
2024-01-03 12:52:03 +00:00
2 changed files with 14 additions and 3 deletions

View File

@ -23,7 +23,7 @@ let run_client sock =
)
let time name service =
Switch.run @@ fun sw ->
Switch.run ~name @@ fun sw ->
let client_sock, server_sock = Eio_unix.Net.socketpair_stream ~sw () in
let t0 = Unix.gettimeofday () in
Fiber.both

View File

@ -69,11 +69,22 @@ let fork_promise_exn ~sw f =
);
p
(* Like [List.iter (fork ~sw)], but runs the last one in the current fiber
for efficiency and less cluttered traces. *)
let rec forks ~sw = function
| [] -> ()
| [x] -> Switch.check sw; x ()
| x :: xs ->
fork ~sw x;
forks ~sw xs
let all xs =
Switch.run ~name:"all" @@ fun sw ->
List.iter (fork ~sw) xs
forks ~sw xs
let both f g = all [f; g]
let both f g =
Switch.run ~name:"both" @@ fun sw ->
forks ~sw [f; g]
let pair f g =
Switch.run ~name:"pair" @@ fun sw ->