Skip to content

Commit c57a9c4

Browse files
committed
Note that canceling a promise does await for the fiber
And also explain the reason behind this design choice within the sample library.
1 parent 4c45b8b commit c57a9c4

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

lib/picos_std.structured/picos_std_structured.mli

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,10 +137,18 @@ module Promise : sig
137137
138138
ℹ️ In addition to using a promise to concurrently compute and return a
139139
value, a cancelable promise can also represent a concurrent fiber that
140-
will continue until it is explicitly {{!try_terminate} canceled}. *)
140+
will continue until it is explicitly {{!try_terminate} canceled}.
141+
142+
⚠️ {{!try_terminate} Canceling} a promise does not immediately terminate
143+
the fiber or wait for the fiber working to complete the promise to
144+
terminate. Constructs like {!Bundle.join_after} and {!Flock.join_after}
145+
only guarantee that all fibers forked within their scope have terminated
146+
before they return or raise. The reason for this design choice in this
147+
library is that synchronization is expensive and delaying synchronization
148+
to the join operation is typically sufficient and amortizes the cost. *)
141149

142150
type !'a t
143-
(** Represents a promise to return value of type ['a]. *)
151+
(** Represents a promise to produce a value of type ['a]. *)
144152

145153
val of_value : 'a -> 'a t
146154
(** [of_value value] returns a constant completed promise that returns the
@@ -155,7 +163,10 @@ module Promise : sig
155163
the [value] that the evaluation of the promise returned, raises the
156164
exception that the evaluation of the promise raised, or raises the
157165
{{!Control.Terminate} [Terminate]} exception in case the promise has been
158-
canceled. *)
166+
canceled.
167+
168+
⚠️ The fiber corresponding to a {{!try_terminate} canceled} promise is not
169+
guaranteed to have terminated at the point [await] raises. *)
159170

160171
val completed : 'a t -> 'a Event.t
161172
(** [completed promise] returns an {{!Picos_std_event.Event} event} that can

0 commit comments

Comments
 (0)