about summary refs log tree commit diff
path: root/src/libstd/comm/select.rs
diff options
context:
space:
mode:
authorAlex Crichton <alex@alexcrichton.com>2013-12-21 22:15:04 -0800
committerAlex Crichton <alex@alexcrichton.com>2014-01-15 11:21:56 -0800
commitadb895a34f6d0b925b8ef877289ca6e3c4d854d4 (patch)
treefc5a2b0a6930d08c9b96e4ef24bdf5ff31adc3ec /src/libstd/comm/select.rs
parent900893112570eea5a01c0573ae1fa1e3a72397e9 (diff)
downloadrust-adb895a34f6d0b925b8ef877289ca6e3c4d854d4.tar.gz
rust-adb895a34f6d0b925b8ef877289ca6e3c4d854d4.zip
Allow more "error" values in try_recv()
This should allow callers to know whether the channel was empty or disconnected
without having to block.

Closes #11087
Diffstat (limited to 'src/libstd/comm/select.rs')
-rw-r--r--src/libstd/comm/select.rs9
1 files changed, 6 insertions, 3 deletions
diff --git a/src/libstd/comm/select.rs b/src/libstd/comm/select.rs
index 302c9d9ea46..fa5ec1d3e30 100644
--- a/src/libstd/comm/select.rs
+++ b/src/libstd/comm/select.rs
@@ -45,6 +45,7 @@
 #[allow(dead_code)];
 
 use cast;
+use comm;
 use iter::Iterator;
 use kinds::Send;
 use ops::Drop;
@@ -279,7 +280,9 @@ impl<'port, T: Send> Handle<'port, T> {
     pub fn recv_opt(&mut self) -> Option<T> { self.port.recv_opt() }
     /// Immediately attempt to receive a value on a port, this function will
     /// never block. Has the same semantics as `Port.try_recv`.
-    pub fn try_recv(&mut self) -> Option<T> { self.port.try_recv() }
+    pub fn try_recv(&mut self) -> comm::TryRecvResult<T> {
+        self.port.try_recv()
+    }
 }
 
 #[unsafe_destructor]
@@ -409,8 +412,8 @@ mod test {
             a = p1.recv() => { assert_eq!(a, 1); },
             a = p2.recv() => { assert_eq!(a, 2); }
         )
-        assert_eq!(p1.try_recv(), None);
-        assert_eq!(p2.try_recv(), None);
+        assert_eq!(p1.try_recv(), Empty);
+        assert_eq!(p2.try_recv(), Empty);
         c3.send(());
     })