File tree Expand file tree Collapse file tree 1 file changed +16
-0
lines changed Expand file tree Collapse file tree 1 file changed +16
-0
lines changed 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