File tree Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Original file line number Diff line number Diff line change @@ -172,6 +172,35 @@ module Control : sig
172
172
(* * [terminate_after ~seconds thunk] arranges to terminate the execution of
173
173
[thunk] on the current fiber after the specified timeout in [seconds].
174
174
175
+ Using [terminate_after] one can conveniently attempt any blocking
176
+ operation that supports cancelation with a timeout. For example, one can
177
+ perform a timed {{!Picos_sync.Ivar.read} [Ivar.read]}
178
+
179
+ {[
180
+ let peek_in ~seconds ivar =
181
+ match
182
+ Control.terminate_after ~seconds @@ fun () ->
183
+ Ivar.read ivar
184
+ with
185
+ | value -> Some value
186
+ | exception Control.Terminate -> None
187
+ ]}
188
+
189
+ or one could try to {{!Picos_stdio.Unix.connect} [connect]} to a socket
190
+ with a timeout
191
+
192
+ {[
193
+ let try_connect_in ~seconds socket sockaddr =
194
+ match
195
+ Control.terminate_after ~seconds @@ fun () ->
196
+ Unix.connect socket sockaddr
197
+ with
198
+ | () -> true
199
+ | exception Control.Terminate -> false
200
+ ]}
201
+
202
+ using the {!Picos_stdio.Unix} module.
203
+
175
204
The optional [callstack] argument specifies the number of callstack
176
205
entries to capture with the {{!Control.Terminate} [Terminate]} exception.
177
206
The default is [0].
You can’t perform that action at this time.
0 commit comments