Module Await.IvarSource

A write-once cell that can be empty or full (i.e., hold a single value).

Sourcetype (!'a : value_or_null) t : value mod contended non_float portable
Sourceval create : ('a : value_or_null). unit -> 'a t @@ portable

create () returns an empty ivar.

Sourceval create_full : ('a : value_or_null). 'a @ portable contended -> 'a t @@ portable

create_full v returns an ivar filled with v.

Sourceval fill_exn : ('a : value_or_null). 'a t @ local -> 'a @ portable contended -> unit @@ portable

fill_exn t v fills t with value v if t was empty.

Sourceval fill_if_empty : ('a : value_or_null). 'a t @ local -> 'a @ portable contended -> unit @@ portable

fill_if_empty t v fills t with value v if t was empty. Otherwise does nothing.

Sourceval read : ('a : value_or_null). Await_kernel.Await.t @ local -> 'a t @ local -> 'a @ portable contended @@ portable

read w t waits until the ivar t is filled and returns the value v after the ivar is filled with v.

  • raises Terminated

    in case w was terminated.

Sourceval read_or_cancel : ('a : value_or_null). Await_kernel.Await.t @ local -> Await_kernel.Cancellation.t @ local -> 'a t @ local -> 'a Await_kernel.Or_canceled.t @ contended @@ portable

read_or_cancel w c t is Completed (read w t) if c was not canceled, otherwise it is Canceled.

  • raises Terminated

    in case w was terminated, even if c was canceled.

Sourceval peek : 'a t @ local -> 'a or_null @ contended @@ portable

peek t returns This v iff t is full with value v, or Null if t is not full.

Note that it's important that for this 'a t, 'a has kind value (and not value_or_null) since in the latter case a non-full t would be distinguishable from a t filled with Null.

Sourceval is_empty : ('a : value_or_null). 'a t @ local -> bool @@ portable

is_empty t returns true if t is empty.

Sourceval is_full : ('a : value_or_null). 'a t @ local -> bool @@ portable

is_full t returns true if t is full.