expose Suspend_ and its internal effect with an unstability alert

This commit is contained in:
Simon Cruanes 2023-07-09 17:34:19 -04:00
parent e855c99bec
commit 12df71c3ab
No known key found for this signature in database
GPG key ID: EBFFF6F283F3A2B4
5 changed files with 20 additions and 11 deletions

View file

@ -9,3 +9,4 @@ module Lock = Lock
module Fork_join = Fork_join
module Fut = Fut
module Pool = Pool
module Suspend_ = Suspend_

View file

@ -77,3 +77,13 @@ module Atomic = Atomic_
This is either a shim using [ref], on pre-OCaml 5, or the
standard [Atomic] module on OCaml 5. *)
(** {2 Suspensions} *)
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. *)

View file

@ -34,6 +34,4 @@ let run_wait_block self (f : unit -> 'a) : 'a =
module For_runner_implementors = struct
let create ~size ~num_tasks ~shutdown ~run_async () : t =
{ size; num_tasks; shutdown; run_async }
module Suspend_ = Suspend_
end

View file

@ -64,13 +64,4 @@ module For_runner_implementors : sig
{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

View file

@ -32,6 +32,15 @@ type suspension_handler = {
*)
[@@@ifge 5.0]
[@@@ocaml.alert "-unstable"]
type _ Effect.t +=
| Suspend : suspension_handler -> unit Effect.t
(** The effect used to suspend the current thread and pass it, suspended,
to the handler. The handler will ensure that the suspension is resumed later
once some computation has been done. *)
[@@@ocaml.alert "+unstable"]
val suspend : suspension_handler -> unit
(** [suspend h] jumps back to the nearest {!with_suspend}