v2 / vlib / v / tests / builtin_arrays / fixed_array_chan_test.v
31 lines · 27 sloc · 362 bytes · 6488041a749df9762348d019c4223908c476f2e2
Raw
1import time
2
3struct Struct {
4 ch chan int
5}
6
7fn listen(ch chan int) {
8 for {
9 t := <-ch or { break }
10 println(t)
11 }
12}
13
14fn sp_array() {
15 mut array := [3]chan int{}
16 for a in 0 .. 3 {
17 spawn listen(array[a])
18 }
19 for i, a in array {
20 a <- i
21 }
22 time.sleep(1000 * time.millisecond)
23 for c in array {
24 c.close()
25 }
26}
27
28fn test_main() {
29 sp_array()
30 assert true
31}
32