File tree Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -1839,6 +1839,34 @@ mod tests {
1839
1839
assert_eq ! ( count_rx. recv( ) . unwrap( ) , 4 ) ;
1840
1840
}
1841
1841
1842
+ #[ test]
1843
+ fn test_recv_try_iter ( ) {
1844
+ let ( request_tx, request_rx) = channel ( ) ;
1845
+ let ( response_tx, response_rx) = channel ( ) ;
1846
+
1847
+ // Request `x`s until we have `6`.
1848
+ let t = thread:: spawn ( move || {
1849
+ let mut count = 0 ;
1850
+ loop {
1851
+ for x in response_rx. try_iter ( ) {
1852
+ count += x;
1853
+ if count == 6 {
1854
+ drop ( response_rx) ;
1855
+ drop ( request_tx) ;
1856
+ return count;
1857
+ }
1858
+ }
1859
+ request_tx. send ( ( ) ) . unwrap ( ) ;
1860
+ }
1861
+ } ) ;
1862
+
1863
+ for _ in request_rx. iter ( ) {
1864
+ response_tx. send ( 2 ) . unwrap ( ) ;
1865
+ }
1866
+
1867
+ assert_eq ! ( t. join( ) . unwrap( ) , 6 ) ;
1868
+ }
1869
+
1842
1870
#[ test]
1843
1871
fn test_recv_into_iter_owned ( ) {
1844
1872
let mut iter = {
You can’t perform that action at this time.
0 commit comments