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