mirror of
https://github.com/c-cube/moonpool.git
synced 2025-12-13 22:40:46 -05:00
add documentation; expose Runner.For_runner_implementors.Suspend_
This commit is contained in:
parent
1d57ae8fbb
commit
39525af7ac
3 changed files with 34 additions and 3 deletions
|
|
@ -34,4 +34,6 @@ let run_wait_block self (f : unit -> 'a) : 'a =
|
||||||
module For_runner_implementors = struct
|
module For_runner_implementors = struct
|
||||||
let create ~size ~num_tasks ~shutdown ~run_async () : t =
|
let create ~size ~num_tasks ~shutdown ~run_async () : t =
|
||||||
{ size; num_tasks; shutdown; run_async }
|
{ size; num_tasks; shutdown; run_async }
|
||||||
|
|
||||||
|
module Suspend_ = Suspend_
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -60,5 +60,17 @@ module For_runner_implementors : sig
|
||||||
run_async:(task -> unit) ->
|
run_async:(task -> unit) ->
|
||||||
unit ->
|
unit ->
|
||||||
t
|
t
|
||||||
(** Create a new runner. *)
|
(** Create a new runner.
|
||||||
|
|
||||||
|
{b NOTE}: the runner should support DLA and {!Suspend_} on OCaml 5.x,
|
||||||
|
so that {!Fork_join} and other 5.x features work properly. *)
|
||||||
|
|
||||||
|
module Suspend_ = Suspend_
|
||||||
|
[@@alert
|
||||||
|
unstable "this module is an implementation detail of moonpool for now"]
|
||||||
|
(** Suspensions.
|
||||||
|
|
||||||
|
This is only going to work on OCaml 5.x.
|
||||||
|
|
||||||
|
{b NOTE}: this is not stable for now. *)
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
(** (Private) suspending tasks using Effects.
|
(** (Private) suspending tasks using Effects.
|
||||||
|
|
||||||
This module is an implementation detail of Moonpool and should
|
This module is an implementation detail of Moonpool and should
|
||||||
not be used outside of it. *)
|
not be used outside of it, except by experts to implement {!Runner}. *)
|
||||||
|
|
||||||
type suspension = (unit, exn * Printexc.raw_backtrace) result -> unit
|
type suspension = (unit, exn * Printexc.raw_backtrace) result -> unit
|
||||||
(** A suspended computation *)
|
(** A suspended computation *)
|
||||||
|
|
@ -12,7 +12,24 @@ type suspension_handler = {
|
||||||
handle: run:(with_handler:bool -> task -> unit) -> suspension -> unit;
|
handle: run:(with_handler:bool -> task -> unit) -> suspension -> unit;
|
||||||
}
|
}
|
||||||
[@@unboxed]
|
[@@unboxed]
|
||||||
(** The handler that knows what to do with the suspended computation *)
|
(** The handler that knows what to do with the suspended computation.
|
||||||
|
|
||||||
|
The handler is given two things:
|
||||||
|
|
||||||
|
- the suspended computation (which can be resumed with a result
|
||||||
|
eventually);
|
||||||
|
- a [run] function that can be used to start tasks to perform some
|
||||||
|
computation.
|
||||||
|
|
||||||
|
This means that a fork-join primitive, for example, can use a single call
|
||||||
|
to {!suspend} to:
|
||||||
|
- suspend the caller until the fork-join is done
|
||||||
|
- use [run] to start all the tasks. Typically [run] is called multiple times,
|
||||||
|
which is where the "fork" part comes from. Each call to [run] potentially
|
||||||
|
runs in parallel with the other calls. The calls must coordinate so
|
||||||
|
that, once they are all done, the suspended caller is resumed with the
|
||||||
|
aggregated result of the computation.
|
||||||
|
*)
|
||||||
|
|
||||||
[@@@ifge 5.0]
|
[@@@ifge 5.0]
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue