We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 3e31eb5 commit e506aa9Copy full SHA for e506aa9
src/store/fs/util/watch.rs
@@ -26,14 +26,22 @@ impl<T> Clone for Sender<T> {
26
pub struct Receiver<T>(Arc<Shared<T>>);
27
28
impl<T> Sender<T> {
29
- pub fn new(value: T) -> Self {
30
- Self(Arc::new(Shared {
31
- value: AtomicRefCell::new(State {
32
- value,
33
- dropped: false,
34
- }),
35
- notify: tokio::sync::Notify::new(),
36
- }))
+
+ pub fn send_modify<F>(&self, modify: F)
+ where
+ F: FnOnce(&mut T),
+ {
+ self.send_if_modified(|value| {
+ modify(value);
+ true
37
+ });
38
+ }
39
40
+ pub fn send_replace(&self, mut value: T) -> T {
41
+ // swap old watched value with the new one
42
+ self.send_modify(|old| std::mem::swap(old, &mut value));
43
44
+ value
45
}
46
47
pub fn send_if_modified<F>(&self, modify: F) -> bool
0 commit comments