mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
all: add builtin channel type chan elem_type
(#6126)
This commit is contained in:
36
vlib/sync/channel_array_mut_test.v
Normal file
36
vlib/sync/channel_array_mut_test.v
Normal file
@ -0,0 +1,36 @@
|
||||
import sync
|
||||
|
||||
const (
|
||||
num_iterations = 10000
|
||||
)
|
||||
|
||||
struct St {
|
||||
mut:
|
||||
n int
|
||||
}
|
||||
|
||||
// this function gets an array of channels for `St` references
|
||||
fn do_rec_calc_send(chs []chan mut St) {
|
||||
mut s := St{}
|
||||
for {
|
||||
if !(&sync.Channel(chs[0])).pop(&s) {
|
||||
break
|
||||
}
|
||||
s.n++
|
||||
(&sync.Channel(chs[1])).push(&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 {
|
||||
(&sync.Channel(chs[0])).push(&t)
|
||||
(&sync.Channel(chs[1])).pop(&t)
|
||||
}
|
||||
(&sync.Channel(chs[0])).close()
|
||||
assert t.n == 100 + num_iterations
|
||||
}
|
Reference in New Issue
Block a user