Expand description
A single-producer, multi-consumer channel that only retains the last sent value.
This channel is useful for watching for changes to a value from multiple points in the code base, for example, changes to configuration values.
Usage
channel
returns a Sender
/ Receiver
pair. These are the producer
and sender halves of the channel. The channel is created with an initial
value. The latest value stored in the channel is accessed with
Receiver::borrow()
. Awaiting Receiver::changed()
waits for a new
value to sent by the Sender
half.
Example
use tarantool::fiber::r#async::watch;
use tarantool::fiber;
let (tx, mut rx) = watch::channel::<i32>(10);
tx.send(20).unwrap();
let value = fiber::block_on(async move {
rx.changed().await.unwrap();
rx.get()
});
Closing
Sender::is_closed
allows the producer to detect
when all Receiver
handles have been dropped. This indicates that there
is no further interest in the values being produced and work can be stopped.
Structs
Future that returns when a new value is published in
Sender
.Error produced when sending a value fails.
Returns a reference to the inner value.
Functions
Creates a new watch channel, returning the “send” and “receive” handles.