2020-09-12 02:29:11 +02:00
|
|
|
fn test_channel_try_buffered() {
|
|
|
|
ch := chan int{cap: 5}
|
2021-05-08 12:32:29 +02:00
|
|
|
for z in 2 .. 13 {
|
2020-09-12 02:29:11 +02:00
|
|
|
if ch.try_push(z) == .not_ready {
|
|
|
|
assert z == 7
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
mut obj := int(0)
|
2021-04-19 10:41:21 +02:00
|
|
|
for ch.try_pop(mut obj) == .success {
|
2020-09-12 02:29:11 +02:00
|
|
|
println(obj)
|
|
|
|
}
|
|
|
|
assert obj == 6
|
|
|
|
ch <- 17
|
|
|
|
obj = <-ch
|
|
|
|
assert obj == 17
|
|
|
|
}
|