1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00
v/vlib/sync/channel_1_test.v

20 lines
313 B
V
Raw Normal View History

2020-08-06 16:28:19 +03:00
const (
num_iterations = 10000
)
fn do_send(ch chan int) {
2020-08-06 16:28:19 +03:00
for i in 0 .. num_iterations {
ch <- i
2020-08-06 16:28:19 +03:00
}
}
fn test_channel_buffered() {
ch := chan int{cap: 1000}
go do_send(ch)
2020-08-06 16:28:19 +03:00
mut sum := i64(0)
for _ in 0 .. num_iterations {
sum += <-ch
2020-08-06 16:28:19 +03:00
}
assert sum == u64(num_iterations) * (num_iterations - 1) / 2
2020-08-06 16:28:19 +03:00
}