Skip to content

Commit d6b9aec

Browse files
committed
---
yaml --- r: 23093 b: refs/heads/master c: c0874db h: refs/heads/master i: 23091: 370b3a8 v: v3
1 parent 9ae3aa4 commit d6b9aec

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: 1beb1f491fdd2d05ca2c05edc966535064c98cf4
2+
refs/heads/master: c0874dbd21c89854c68e8db7201f5557ab5e6259
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: cd6f24f9d14ac90d167386a56e7a6ac1f0318195
55
refs/heads/try: ffbe0e0e00374358b789b0037bcb3a577cd218be

trunk/src/libcore/pipes.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -877,6 +877,9 @@ trait channel<T: send> {
877877

878878
/// Sends a message.
879879
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;
880883
}
881884

882885
/// A trait for things that can receive multiple messages.
@@ -931,6 +934,18 @@ impl chan<T: send> of channel<T> for chan<T> {
931934
self.endp = some(
932935
streamp::client::data(unwrap(endp), x))
933936
}
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+
}
934949
}
935950

936951
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> {
10471062
chan.send(option::unwrap(x))
10481063
}
10491064
}
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+
}
10501074
}
10511075

10521076
/// Converts a `chan` into a `shared_chan`.

0 commit comments

Comments
 (0)