File tree Expand file tree Collapse file tree 2 files changed +18
-1
lines changed
Expand file tree Collapse file tree 2 files changed +18
-1
lines changed Original file line number Diff line number Diff line change @@ -247,7 +247,7 @@ impl<T> Receiver<T> {
247247 /// [`changed`]: Receiver::changed
248248 pub fn borrow_and_update ( & mut self ) -> Ref < ' _ , T > {
249249 let inner = self . shared . value . read ( ) . unwrap ( ) ;
250- self . version = self . shared . version . load ( SeqCst ) ;
250+ self . version = self . shared . version . load ( SeqCst ) & ! CLOSED ;
251251 Ref { inner }
252252 }
253253
Original file line number Diff line number Diff line change @@ -169,3 +169,20 @@ fn poll_close() {
169169
170170 assert ! ( tx. send( "two" ) . is_err( ) ) ;
171171}
172+
173+ #[ test]
174+ fn borrow_and_update ( ) {
175+ let ( tx, mut rx) = watch:: channel ( "one" ) ;
176+
177+ tx. send ( "two" ) . unwrap ( ) ;
178+ assert_ready ! ( spawn( rx. changed( ) ) . poll( ) ) . unwrap ( ) ;
179+ assert_pending ! ( spawn( rx. changed( ) ) . poll( ) ) ;
180+
181+ tx. send ( "three" ) . unwrap ( ) ;
182+ assert_eq ! ( * rx. borrow_and_update( ) , "three" ) ;
183+ assert_pending ! ( spawn( rx. changed( ) ) . poll( ) ) ;
184+
185+ drop ( tx) ;
186+ assert_eq ! ( * rx. borrow_and_update( ) , "three" ) ;
187+ assert_ready ! ( spawn( rx. changed( ) ) . poll( ) ) . unwrap_err ( ) ;
188+ }
You can’t perform that action at this time.
0 commit comments