v2 / vlib / v / tests / loops / for_select_test.v
27 lines · 24 sloc · 299 bytes · 6488041a749df9762348d019c4223908c476f2e2
Raw
1import time
2
3fn test_main() {
4 ch := chan int{}
5 go do_send(ch)
6 mut a := 0
7 for select {
8 x := <-ch {
9 a += x
10 check(x)
11 }
12 } {
13 }
14 assert a == 45
15 time.sleep(500 * time.millisecond)
16}
17
18fn do_send(ch chan int) {
19 for i in 0 .. 10 {
20 ch <- i
21 }
22 ch.close()
23}
24
25fn check(a int) {
26 println(a)
27}
28