File tree Expand file tree Collapse file tree 2 files changed +25
-0
lines changed Expand file tree Collapse file tree 2 files changed +25
-0
lines changed Original file line number Diff line number Diff line change @@ -63,6 +63,11 @@ module Computation = struct
63
63
let balance_and_mode = Bool. to_int (mode == `FIFO ) in
64
64
Atomic. make (Continue { balance_and_mode; triggers = [] })
65
65
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
+
66
71
let is_canceled t =
67
72
match Atomic. get t with
68
73
| Canceled _ -> true
Original file line number Diff line number Diff line change @@ -745,6 +745,26 @@ module Computation : sig
745
745
val wait : _ t -> unit
746
746
(* * [wait computation] waits for the computation to complete. *)
747
747
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
+
748
768
(* * {2 Interface for propagating cancelation} *)
749
769
750
770
val canceler : from :_ t -> into :_ t -> Trigger .t
You can’t perform that action at this time.
0 commit comments