Module Await_kernel.Terminator

A termination token represents an implicit and unexpected interrupt request to be used in case of panics.

type t

t is the type of termination tokens. Tokens become terminated by calls to Source.terminate.

val is_terminated : t @ local -> bool @@ portable

is_terminated t is true if t has been terminated and false otherwise. Once is_terminated t is true it will never again become false.

val same : t @ local -> (t @ local -> bool) @ local @@ portable

same t1 t2 determines whether the tokens t1 and t2 are the one and the same.

val never : t @@ portable

never is a termination token that is never terminated

val always : t @@ portable

always is a termination token that is already terminated.

module Source : sig ... end
val is_terminatable : t @ local -> bool @@ portable

is_terminatable t is true if the token has an associated source and can be terminated through it and otherwise false.

val source : t @ local -> Source.t or_null @@ portable

source t returns the source of the termination token This t or Null in case the token is not terminatable.

val with_ : 'a. (t @ local -> 'a) @ local once -> 'a @@ portable

with_ f creates a fresh termination token with an associated source and passes both to f. The token is terminated when Source.terminate has been called on the source.

Panics if t still has unsignaled attached triggers when f finishes.

val with_linked : 'a. t @ local -> ((t @ local -> 'a) @ local once -> 'a) @ local @@ portable

with_linked t f creates a fresh termination token with an associated source and passes both to f. The token is terminated when either t is terminated or Source.terminate has been called on the source.

Panics if t still has unsignaled attached triggers when f finishes.

val with_linked_multi : 'a. t list @ local -> ((t @ local -> 'a) @ local once -> 'a) @ local @@ portable

with_linked_multi ts f creates a fresh termination token with an associated source and passes them both to f. The token is canceled when any of ts are terminated or when Source.terminate has been called on the source.

Panics if t still has unsignaled attached triggers when f finishes.

val add_trigger : t @ local -> (Trigger.Source.t -> Link.t) @ local @@ portable

add_trigger t s attaches s to the token t so that it will be signalled when t is terminated.

Returns

  • Terminated if t was already terminated and so s was not attached to it,
  • Signaled if s was already signaled and so wasn't attached to t, or
  • Attached if t was not terminated and s was not signaled and so s has been attached to t.

add_trigger does not update the trigger s. In particular, a return value of Terminated tells nothing about the state of s.

val cancellation : t @ local -> Cancellation.t @ local @@ portable

cancellation t is the underlying cancellation token of the terminator t.

This allows turning termination into cancellation for the purpose of carefully handling resources in critical sections where implicit termination is not desired.

module Expert : sig ... end