v / vlib / sync
Raw file | 17 loc (17 sloc) | 281 bytes | Latest commit hash 8a380f469
1fn test_channel_try_buffered() {
2 ch := chan int{cap: 5}
3 for z in 2 .. 13 {
4 if ch.try_push(z) == .not_ready {
5 assert z == 7
6 break
7 }
8 }
9 mut obj := int(0)
10 for ch.try_pop(mut obj) == .success {
11 println(obj)
12 }
13 assert obj == 6
14 ch <- 17
15 obj = <-ch
16 assert obj == 17
17}