package fiber

  1. Overview
  2. Docs
Structured concurrency library

Install

Dune Dependency

Authors

Maintainers

Sources

dune-3.6.1.tbz
sha256=f1d5ac04b7a027f3d549e25cf885ebf7acc135e0291c18e6b43123a799c143ce
sha512=64714ab6155cd04bc33d693fc7a6d9d61aa7a278357eeff159df324e083914fcd556459a3945acacf1bbc3775f2232ab0c78006ab8a434dc58dcf95ffdffac52

doc/fiber/Fiber/Svar/index.html

Module Fiber.SvarSource

State variables

A "state variable" Svar.t differs from Ivar.t in that it can be updated multiple times. It is particularly useful if you'd like to observe the state of a process by subscribing to "interesting" (from your perspective) events.

For example, a build system can have a complex state machine, switching between states like "waiting for source file changes", "building", etc., by calling Svar.write on the corresponding state variable. If you don't care about most of the states but would like to observe all errors, you can use Svar.wait ~until:is_error to be woken up when an error happens. Other observers may have different preferences, expressed with different until predicates. You can also use the non-blocking Svar.read if you'd like to use polling instead.

Sourcetype 'a t

'a t is a state variable holding the value of type 'a

Sourceval create : 'a -> 'a t

create init creates a new state variable initialized with init

Sourceval read : 'a t -> 'a

read t returns the current value of t

Sourceval wait : 'a t -> until:('a -> bool) -> unit fiber

wait t ~until waits until t's value satisfies the predicate until. If the current value satisfies it, wait returns immediately, otherwise, the caller is blocked.

Sourceval write : 'a t -> 'a -> unit fiber

write t a sets the current value of t to a

OCaml

Innovation. Community. Security.