File tree Expand file tree Collapse file tree 1 file changed +24
-0
lines changed Expand file tree Collapse file tree 1 file changed +24
-0
lines changed Original file line number Diff line number Diff line change @@ -877,6 +877,9 @@ trait channel<T: send> {
877
877
878
878
/// Sends a message.
879
879
fn send(+x: T);
880
+
881
+ /// Sends a message, or report if the receiver has closed the connection.
882
+ fn try_send(+x: T) -> bool;
880
883
}
881
884
882
885
/// A trait for things that can receive multiple messages.
@@ -931,6 +934,18 @@ impl chan<T: send> of channel<T> for chan<T> {
931
934
self.endp = some(
932
935
streamp::client::data(unwrap(endp), x))
933
936
}
937
+
938
+ fn try_send(+x: T) -> bool {
939
+ let mut endp = none;
940
+ endp <-> self.endp;
941
+ match move streamp::client::try_data(unwrap(endp), x) {
942
+ some(next) => {
943
+ self.endp = some(move_it!(next));
944
+ true
945
+ }
946
+ none => false
947
+ }
948
+ }
934
949
}
935
950
936
951
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> {
1047
1062
chan.send(option::unwrap(x))
1048
1063
}
1049
1064
}
1065
+
1066
+ fn try_send(+x: T) -> bool {
1067
+ let mut xx = some(x);
1068
+ do self.with |chan| {
1069
+ let mut x = none;
1070
+ x <-> xx;
1071
+ chan.try_send(option::unwrap(x))
1072
+ }
1073
+ }
1050
1074
}
1051
1075
1052
1076
/// Converts a `chan` into a `shared_chan`.
You can’t perform that action at this time.
0 commit comments