v/vlib/sync/channel_1_test.v

24 lines
367 B
V
Raw Normal View History

2020-08-06 15:28:19 +02:00
import sync
const (
num_iterations = 10000
)
fn do_send(mut ch sync.Channel) {
for i in 0 .. num_iterations {
ch.push(&i)
}
}
fn test_channel_buffered() {
mut ch := sync.new_channel<int>(1000)
go do_send(mut ch)
mut sum := i64(0)
for _ in 0 .. num_iterations {
a := 0
ch.pop(&a)
sum += a
}
assert sum == u64(num_iterations)*(num_iterations-1)/2
}