1 | const ( |
2 | num_iterations = 10000 |
3 | ) |
4 | |
5 | struct St { |
6 | mut: |
7 | dummy i64 |
8 | dummy2 u32 |
9 | dummy3 i64 |
10 | n int |
11 | dummy4 int |
12 | } |
13 | |
14 | // this function gets an array of channels for `St` references |
15 | fn do_rec_calc_send(chs []chan mut St) { |
16 | for { |
17 | mut s := <-chs[0] or { break } |
18 | s.n++ |
19 | chs[1] <- s |
20 | } |
21 | } |
22 | |
23 | fn test_channel_array_mut() { |
24 | mut chs := [chan mut St{cap: 1}, chan mut St{}] |
25 | spawn do_rec_calc_send(chs) |
26 | mut t := &St{ |
27 | n: 100 |
28 | } |
29 | for _ in 0 .. num_iterations { |
30 | chs[0] <- t |
31 | t = <-chs[1] |
32 | } |
33 | chs[0].close() |
34 | assert t.n == 100 + num_iterations |
35 | } |