Library
Module
Module type
Parameter
Class
Class type
This module provides a way to cancel long running computations. Cancellation is fully explicit and fibers must explicitly check for it at strategic points.
val create : unit -> t
Activate a cancellation request.
fire
is idempotent, so calling fire t
more than once has no effect.
Version of fire
that is suitable to call from the iter
callback of Fiber.run
.
val fired : t -> bool
Return whether the given cancellation has been fired.
val with_handler :
t ->
(unit -> 'a fiber) ->
on_cancel:(unit -> 'b fiber) ->
('a * 'b outcome) fiber
with_handler t ~on_cancel f
runs f ()
with a cancellation handler. If t
is fired during the execution of f
, then on_cancel
is called.
The aim of on_cancel
is to somehow cut short the execution of f
. A typical example is a function running an external command. on_cancel
might send a KILL
signal to the command to abort its execution.
If f ()
finished before t
is fired, then on_cancel
will never be invoked.