Skip to content

Commit 8deffa8

Browse files
committed
Add Computation.with_action
1 parent ea13e24 commit 8deffa8

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

lib/picos/bootstrap/picos_bootstrap.ml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,11 @@ module Computation = struct
6363
let balance_and_mode = Bool.to_int (mode == `FIFO) in
6464
Atomic.make (Continue { balance_and_mode; triggers = [] })
6565

66+
let with_action ?(mode : [ `FIFO | `LIFO ] = `FIFO) x y action =
67+
let balance_and_mode = one + Bool.to_int (mode == `FIFO) in
68+
let trigger = Trigger.from_action x y action in
69+
Atomic.make (Continue { balance_and_mode; triggers = [ trigger ] })
70+
6671
let is_canceled t =
6772
match Atomic.get t with
6873
| Canceled _ -> true

lib/picos/picos.mli

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -745,6 +745,26 @@ module Computation : sig
745745
val wait : _ t -> unit
746746
(** [wait computation] waits for the computation to complete. *)
747747

748+
val with_action :
749+
?mode:[ `FIFO | `LIFO ] ->
750+
'x ->
751+
'y ->
752+
(Trigger.t -> 'x -> 'y -> unit) ->
753+
'a t
754+
[@@alert
755+
handler
756+
"This is an escape hatch for experts implementing schedulers or \
757+
structured concurrency mechanisms. If you know what you are doing, use \
758+
[@alert \"-handler\"]."]
759+
(** [with_action x y resume] is equivalent to
760+
{@ocaml skip[
761+
let computation = create () in
762+
let trigger = Trigger.from_action x y resume in
763+
let _ : bool = try_attach computation trigger in
764+
computation
765+
]}
766+
⚠️ The same warnings as with {!Trigger.from_action} apply. *)
767+
748768
(** {2 Interface for propagating cancelation} *)
749769

750770
val canceler : from:_ t -> into:_ t -> Trigger.t

0 commit comments

Comments
 (0)