This commit is contained in:
Simon Cruanes 2024-02-27 22:48:23 -05:00
parent 42d16465c3
commit a2ea24551b
No known key found for this signature in database
GPG key ID: EBFFF6F283F3A2B4

View file

@ -10,6 +10,16 @@ type suspension_handler = {
}
[@@unboxed]
type with_suspend_handler =
| WSH : {
on_suspend: unit -> 'state;
(** on_suspend called when [f()] suspends itself. *)
run: 'state -> task -> unit; (** run used to schedule new tasks *)
resume: 'state -> suspension -> unit Exn_bt.result -> unit;
(** resume run the suspension. Must be called exactly once. *)
}
-> with_suspend_handler
[@@@ifge 5.0]
[@@@ocaml.alert "-unstable"]
@ -22,16 +32,6 @@ type _ Effect.t +=
let[@inline] yield () = Effect.perform Yield
let[@inline] suspend h = Effect.perform (Suspend h)
type with_suspend_handler =
| WSH : {
on_suspend: unit -> 'state;
(** on_suspend called when [f()] suspends itself. *)
run: 'state -> task -> unit; (** run used to schedule new tasks *)
resume: 'state -> suspension -> unit Exn_bt.result -> unit;
(** resume run the suspension. Must be called exactly once. *)
}
-> with_suspend_handler
let with_suspend (WSH { on_suspend; run; resume }) (f : unit -> unit) : unit =
let module E = Effect.Deep in
(* effect handler *)