Module Awaitable.Awaiter

An expert interface that allows an await to be setup separately from suspending the thread of control. This makes it possible to e.g. implement condition variables, which requires setting up the await before unlocking the associated mutex, and also makes it possible to await for one of many things.

type ('a : value_or_null) awaitable := 'a t
type t

Represents a single use awaiter of a signal to an awaitable.

val create_and_add : 'a. 'a awaitable -> Await_kernel.Trigger.Source.t -> until_phys_unequal_to:'a @ portable contended -> t

create_and_add t s ~until_phys_unequal_to:v creates a single-use awaiter with the given trigger t, adds the awaiter to the FIFO associated with the awaitable t, and returns the awaiter.

val cancel_and_remove : t @ local -> unit

cancel_and_remove a signals the trigger of the awaiter a and cancels the awaiter such that it will not be selected by signal or broadcast, and removes the awaiter a from the awaitable into which a was originally added.

This can be called even after something has already signaled the trigger of the awaiter a. In such cases cancel_and_remove will signal another awaiter on the awaitable, if one is available, so that the other awaiter can react to the signal instead.

If the associated trigger is used with only one awaiter and the await on the trigger was neither terminated nor canceled, there is no need to explicitly cancel_and_remove, because the awaiter a has already been used and removed from the awaitable .