about summary refs log tree commit diff
path: root/src/libstd
diff options
context:
space:
mode:
authormitchmindtree <mitchell.nordine@gmail.com>2016-07-09 00:21:26 +1000
committermitchmindtree <mitchell.nordine@gmail.com>2016-07-09 00:21:26 +1000
commitb354887180b665441dd6e3ea51b2651085de88f9 (patch)
treedfa4c07c831ce0aa4cfe26ce9bbddd7437450443 /src/libstd
parent8aeb9303e954502f67f4af7c5c7e79f6d4f706eb (diff)
downloadrust-b354887180b665441dd6e3ea51b2651085de88f9.tar.gz
rust-b354887180b665441dd6e3ea51b2651085de88f9.zip
Add a test for Receiver::try_iter
Diffstat (limited to 'src/libstd')
-rw-r--r--src/libstd/sync/mpsc/mod.rs28
1 files changed, 28 insertions, 0 deletions
diff --git a/src/libstd/sync/mpsc/mod.rs b/src/libstd/sync/mpsc/mod.rs
index 30ce9c3f382..51a820b2e91 100644
--- a/src/libstd/sync/mpsc/mod.rs
+++ b/src/libstd/sync/mpsc/mod.rs
@@ -1840,6 +1840,34 @@ mod tests {
     }
 
     #[test]
+    fn test_recv_try_iter() {
+        let (request_tx, request_rx) = channel();
+        let (response_tx, response_rx) = channel();
+
+        // Request `x`s until we have `6`.
+        let t = thread::spawn(move|| {
+            let mut count = 0;
+            loop {
+                for x in response_rx.try_iter() {
+                    count += x;
+                    if count == 6 {
+                        drop(response_rx);
+                        drop(request_tx);
+                        return count;
+                    }
+                }
+                request_tx.send(()).unwrap();
+            }
+        });
+
+        for _ in request_rx.iter() {
+            response_tx.send(2).unwrap();
+        }
+
+        assert_eq!(t.join().unwrap(), 6);
+    }
+
+    #[test]
     fn test_recv_into_iter_owned() {
         let mut iter = {
           let (tx, rx) = channel::<i32>();