File tree Expand file tree Collapse file tree 2 files changed +17
-1
lines changed Expand file tree Collapse file tree 2 files changed +17
-1
lines changed Original file line number Diff line number Diff line change 2
2
refs/heads/master: 61b1875c16de39c166b0f4d54bba19f9c6777d1a
3
3
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
4
4
refs/heads/snap-stage3: 4a81779abd786ff22d71434c6d9a5917ea4cdfff
5
- refs/heads/try: a53a08e1b980e5cf5f9707ef1d1f27b89ff7ed99
5
+ refs/heads/try: b157f0b263fba5a1c7e8e80a744f6f22ff3c7276
6
6
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
Original file line number Diff line number Diff line change @@ -26,6 +26,7 @@ import task;
26
26
27
27
export send;
28
28
export recv;
29
+ export peek;
29
30
export chan:: { } ;
30
31
export port:: { } ;
31
32
@@ -153,6 +154,11 @@ fn recv_<T: send>(p: *rust_port) -> T {
153
154
ret res;
154
155
}
155
156
157
+ #[ doc = "Returns true if there are messages available" ]
158
+ fn peek < T : send > ( p : port < T > ) -> bool {
159
+ rustrt:: rust_port_size ( * * * p) != 0 u as ctypes:: size_t
160
+ }
161
+
156
162
#[ doc(
157
163
brief = "Constructs a channel. The channel is bound to the \
158
164
port used to construct it."
@@ -203,3 +209,13 @@ fn chan_chan() {
203
209
recv ( p) ;
204
210
}
205
211
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
+ }
You can’t perform that action at this time.
0 commit comments