Module B0_std.Bval

Blocking values.

Note. In direct style the Fut.t values would go away. For now be bundled lazy blocking values in the same structure.

type 'a setter

The type for setting blocking value.

type 'a t

The type for immutable blocking values.

val make : unit -> 'a t * 'a setter

make () is a blocking value and a setter to set it.

val of_val : 'a -> 'a t

of_val v is a (non-)blocking value holding v.

val of_lazy_fun : (unit -> 'a) -> 'a t

of_lazy_fun f is a blocking value that runs f iff get or poll is called on the value.

XXX. Something should be said about the context in which f runs.

val of_setter : 'a setter -> 'a t

of_setter s is the blocking value of s.

val is_lazy : 'a t -> bool

is_lazy bv is true iff bv is a lazily triggered value.


val set : 'a setter -> 'a -> unit

set s v sets the blocking value of_setter s to value v. Raises Invalid_argument if set is already set.

val try_set : 'a setter -> 'a -> bool

try_set s v is true if iv was set to v and false if iv was already set.


val get : 'a t -> 'a Fut.t

get bv is the value of bv. In direct style, this should be a blocking call.

val poll : 'a t -> 'a option

poll bv is None if get bv would block and Some _ if it does not block. If bv was created with of_lazy_fun, this ensure the computation gets triggered.

val stir : 'a t -> unit

stir bv is ignore (poll v). Useful if you know bv will be needed later and may be a of_lazy_fun.


val pp : 'a Fmt.t -> 'a t Fmt.t

pp formats blocking values. Does not block if the value is not set in which case "<pending>" formatted.