about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--src/libcore/pipes.rs24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/libcore/pipes.rs b/src/libcore/pipes.rs
index c72a777c0a8..e455d22e70e 100644
--- a/src/libcore/pipes.rs
+++ b/src/libcore/pipes.rs
@@ -877,6 +877,9 @@ trait channel<T: send> {
 
     /// Sends a message.
     fn send(+x: T);
+
+    /// Sends a message, or report if the receiver has closed the connection.
+    fn try_send(+x: T) -> bool;
 }
 
 /// A trait for things that can receive multiple messages.
@@ -931,6 +934,18 @@ impl chan<T: send> of channel<T> for chan<T> {
         self.endp = some(
             streamp::client::data(unwrap(endp), x))
     }
+
+    fn try_send(+x: T) -> bool {
+        let mut endp = none;
+        endp <-> self.endp;
+        match move streamp::client::try_data(unwrap(endp), x) {
+            some(next) => {
+                self.endp = some(move_it!(next));
+                true
+            }
+            none => false
+        }
+    }
 }
 
 impl port<T: send> of recv<T> for port<T> {
@@ -1047,6 +1062,15 @@ impl chan<T: send> of channel<T> for shared_chan<T> {
             chan.send(option::unwrap(x))
         }
     }
+
+    fn try_send(+x: T) -> bool {
+        let mut xx = some(x);
+        do self.with |chan| {
+            let mut x = none;
+            x <-> xx;
+            chan.try_send(option::unwrap(x))
+        }
+    }
 }
 
 /// Converts a `chan` into a `shared_chan`.