package fiber

  1. Overview
  2. Docs

Fiber cancellation

This module provides a way to cancel long running computations. Cancellation is fully explicit and fibers must explicitely check for it at strategic points.

type t
val create : unit -> t
val fire : t -> unit fiber

Activate a cancellation request.

fire is idempotent, so calling fire t more than once has no effect.

val fire' : t -> fill list

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.

type 'a outcome =
  1. | Cancelled of 'a
  2. | Not_cancelled
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.

OCaml

Innovation. Community. Security.