package moonpool

  1. Overview
  2. Docs
Pools of threads supported by a pool of domains

Install

Dune Dependency

Authors

Maintainers

Sources

moonpool-0.7.tbz
sha256=c4a1f974200530ab7f6014de3a369fdbb260ff454183640f32e51ba3fec51b15
sha512=865daabb96e3d60f88ecee9fc9030dad8b257fff4121b404e882d8a8d6687b737beb6e22366f52eb14e770dfab28b326853a1d3d883fa19bbd791d8450b40f8b

doc/src/moonpool.fib/main.ml.html

Source file main.ml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
exception Oh_no of Exn_bt.t

let main (f : Runner.t -> 'a) : 'a =
  let worker_st =
    Fifo_pool.Private_.create_single_threaded_state ~thread:(Thread.self ())
      ~on_exn:(fun e bt -> raise (Oh_no (Exn_bt.make e bt)))
      ()
  in
  let runner = Fifo_pool.Private_.runner_of_state worker_st in
  try
    let fiber = Fiber.spawn_top ~on:runner (fun () -> f runner) in
    Fiber.on_result fiber (fun _ -> Runner.shutdown_without_waiting runner);

    (* run the main thread *)
    Moonpool.Private.Worker_loop_.worker_loop worker_st
      ~ops:Fifo_pool.Private_.worker_ops;

    match Fiber.peek fiber with
    | Some (Ok x) -> x
    | Some (Error ebt) -> Exn_bt.raise ebt
    | None -> assert false
  with Oh_no ebt -> Exn_bt.raise ebt
OCaml

Innovation. Community. Security.