File tree Expand file tree Collapse file tree 2 files changed +44
-0
lines changed Expand file tree Collapse file tree 2 files changed +44
-0
lines changed Original file line number Diff line number Diff line change @@ -669,6 +669,17 @@ impl<T> Receiver<T> {
669
669
self . version . decrement ( ) ;
670
670
}
671
671
672
+ /// Marks the state as unchanged.
673
+ ///
674
+ /// The current value will be considered seen by the receiver.
675
+ ///
676
+ /// This is useful if you are not interested in the current value
677
+ /// visible in the receiver.
678
+ pub fn mark_unchanged ( & mut self ) {
679
+ let current_version = self . shared . state . load ( ) . version ( ) ;
680
+ self . version = current_version;
681
+ }
682
+
672
683
/// Waits for a change notification, then marks the newest value as seen.
673
684
///
674
685
/// If the newest value in the channel has not yet been marked seen when
Original file line number Diff line number Diff line change @@ -102,6 +102,39 @@ fn rx_mark_changed() {
102
102
assert_eq ! ( * rx. borrow( ) , "two" ) ;
103
103
}
104
104
105
+ #[ test]
106
+ fn rx_mark_unchanged ( ) {
107
+ let ( tx, mut rx) = watch:: channel ( "one" ) ;
108
+
109
+ let mut rx2 = rx. clone ( ) ;
110
+
111
+ {
112
+ assert ! ( !rx. has_changed( ) . unwrap( ) ) ;
113
+
114
+ rx. mark_changed ( ) ;
115
+ assert ! ( rx. has_changed( ) . unwrap( ) ) ;
116
+
117
+ rx. mark_unchanged ( ) ;
118
+ assert ! ( !rx. has_changed( ) . unwrap( ) ) ;
119
+
120
+ let mut t = spawn ( rx. changed ( ) ) ;
121
+ assert_pending ! ( t. poll( ) ) ;
122
+ }
123
+
124
+ {
125
+ assert ! ( !rx2. has_changed( ) . unwrap( ) ) ;
126
+
127
+ tx. send ( "two" ) . unwrap ( ) ;
128
+ assert ! ( rx2. has_changed( ) . unwrap( ) ) ;
129
+
130
+ rx2. mark_unchanged ( ) ;
131
+ assert ! ( !rx2. has_changed( ) . unwrap( ) ) ;
132
+ assert_eq ! ( * rx2. borrow_and_update( ) , "two" ) ;
133
+ }
134
+
135
+ assert_eq ! ( * rx. borrow( ) , "two" ) ;
136
+ }
137
+
105
138
#[ test]
106
139
fn multi_rx ( ) {
107
140
let ( tx, mut rx1) = watch:: channel ( "one" ) ;
You can’t perform that action at this time.
0 commit comments