summaryrefslogtreecommitdiffstats
path: root/tokio/src/sync/mod.rs
diff options
context:
space:
mode:
authorCarl Lerche <me@carllerche.com>2020-09-11 15:14:45 -0700
committerGitHub <noreply@github.com>2020-09-11 15:14:45 -0700
commit2bc9a4815259c8ff4daa5e24f128ec826970d17f (patch)
treec075e4d97a145ce104cfc8ee39d8d06acece5c13 /tokio/src/sync/mod.rs
parentc5a9ede157691ac5ca15283735bd666c6b016188 (diff)
sync: tweak `watch` API (#2814)
Decouples getting the latest `watch` value from receiving the change notification. The `Receiver` async method becomes `Receiver::changed()`. The latest value is obtained from `Receiver::borrow()`. The implementation is updated to use `Notify`. This requires adding `Notify::notify_waiters`. This method is generally useful but is kept private for now.
Diffstat (limited to 'tokio/src/sync/mod.rs')
-rw-r--r--tokio/src/sync/mod.rs10
1 files changed, 4 insertions, 6 deletions
diff --git a/tokio/src/sync/mod.rs b/tokio/src/sync/mod.rs
index d5004137..522205a0 100644
--- a/tokio/src/sync/mod.rs
+++ b/tokio/src/sync/mod.rs
@@ -355,10 +355,8 @@
//! let op = my_async_operation();
//! tokio::pin!(op);
//!
-//! // Receive the **initial** configuration value. As this is the
-//! // first time the config is received from the watch, it will
-//! // always complete immediatedly.
-//! let mut conf = rx.recv().await;
+//! // Get the initial config value
+//! let mut conf = rx.borrow().clone();
//!
//! let mut op_start = Instant::now();
//! let mut delay = time::delay_until(op_start + conf.timeout);
@@ -375,8 +373,8 @@
//! // Restart the timeout
//! delay = time::delay_until(op_start + conf.timeout);
//! }
-//! new_conf = rx.recv() => {
-//! conf = new_conf;
+//! _ = rx.changed() => {
+//! conf = rx.borrow().clone();
//!
//! // The configuration has been updated. Update the
//! // `delay` using the new `timeout` value.