Skip to content

Commit 5bf6680

Browse files
committed
---
yaml --- r: 14299 b: refs/heads/try c: b157f0b h: refs/heads/master i: 14297: 1cda0f3 14295: cc050bf v: v3
1 parent de0e6d0 commit 5bf6680

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
refs/heads/master: 61b1875c16de39c166b0f4d54bba19f9c6777d1a
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 4a81779abd786ff22d71434c6d9a5917ea4cdfff
5-
refs/heads/try: a53a08e1b980e5cf5f9707ef1d1f27b89ff7ed99
5+
refs/heads/try: b157f0b263fba5a1c7e8e80a744f6f22ff3c7276
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105

branches/try/src/libcore/comm.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import task;
2626

2727
export send;
2828
export recv;
29+
export peek;
2930
export chan::{};
3031
export port::{};
3132

@@ -153,6 +154,11 @@ fn recv_<T: send>(p: *rust_port) -> T {
153154
ret res;
154155
}
155156

157+
#[doc = "Returns true if there are messages available"]
158+
fn peek<T: send>(p: port<T>) -> bool {
159+
rustrt::rust_port_size(***p) != 0u as ctypes::size_t
160+
}
161+
156162
#[doc(
157163
brief = "Constructs a channel. The channel is bound to the \
158164
port used to construct it."
@@ -203,3 +209,13 @@ fn chan_chan() {
203209
recv(p);
204210
}
205211

212+
#[test]
213+
fn test_peek() {
214+
let po = port();
215+
let ch = chan(po);
216+
assert !peek(po);
217+
send(ch, ());
218+
assert peek(po);
219+
recv(po);
220+
assert !peek(po);
221+
}

0 commit comments

Comments
 (0)