Mvar is a mutable location that is either empty or contains a value. One can
set the value, and wait on
value_available for the location to be filled
in either way.
Mvar.Writer.t gives the capability to mutate the mvar.
The key difference between an
Mvar and an
Ivar is that an
Mvar may be filled
This implementation of
Mvar also allows one to replace the value without any
guarantee that the reading side has seen it. This is useful in situations where
last-value semantics are desired (i.e. you want to signal whenever a config file is
updated, but only care about the most recent values).
Mvar can also be used as a baton passing mechanism between a producer
and consumer. For instance, a producer reading from a socket and producing
a set of deserialized messages can put the batch from a single read into an
Mvar and can wait for
taken to return as a pushback mechanism. The
consumer meanwhile waits on
value_available. This way the natural batch
size is passed between the two sub-systems with minimal overhead.
set t a sets the value in
a, even if
not (is_empty t). This is useful if
you want takers to have last-value semantics.
value_available t returns a deferred
d that becomes determined when a value is in
d does not include the value in
t because that value may change after
becomes determined and before a deferred bind on
d gets to run.
Repeated calls to
value_available will always return the same deferred until
take t returns the value in
t and clears
t, or returns
take_exn is like
take, except it raises if
peek t returns the value in
t without clearing
t, or returns
peek_exn t is like
peek, except it raises if