This module defines the Run_in_fork module for Async_extended.Std. It is useful when performing long-running calculations that need data from the parent, and which would otherwise block async.

See lib/async_extended/example/ for an example.

val run_in_fork : ?max_len:int -> bin_t:'b Core.Bin_prot.Type_class.t -> f:(unit -> 'b) -> unit -> 'b Core.Or_error.t Async.Deferred.t

run_in_fork forks and then runs f in the child process, and then writes the result back to the parent process over a unix pipe. Note that f cannot contain any async calculations. An Error will be returned if an exception is thrown in the child, or the child disconnects before writing the result.

type 'a ret =
  1. | Part of 'a
  2. | Err of Core.Error.t
  3. | Done
val run_in_fork_multiple : ?max_len:int -> bin_t:'b Core.Bin_prot.Type_class.t -> f:(write:('b -> unit) -> unit) -> unit -> 'b ret Async.Pipe.Reader.t

run_in_fork_multiple is just like run_in_fork but allows the user to write multiple results from the child to the parent. This is useful when the the data being written over the pipe is very large, as deserializing the data may take a long time, and the user may want to split the data into smaller chunks.