ocaml-multicore / picos

Interoperable effects based concurrency
https://ocaml-multicore.github.io/picos/doc/picos/index.html
ISC License
86 stars 3 forks source link

Add optional argument to terminate `Bundle` and `Flock` on return #235

Closed polytypic closed 2 months ago

polytypic commented 2 months ago

Having a Bundle or Flock terminate fibers on return is often convenient. In particular, this is convenient for setting up a bundle for daemon fibers:

Bundle.join_after ~on_return:`Terminate @@ fun daemons ->
Bundle.fork daemons (fun () -> (* ... *))
(* ... *)

Another alternative (one of many) is to fork as a promise and use a finalizer:

let@ _daemon =
  finally Promise.terminate @@ fun () ->
  Flock.fork_as_promise @@ fun () ->
  (* ... *)
in
(* ... *)