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