v / vlib / sync
Raw file | 19 loc (17 sloc) | 309 bytes | Latest commit hash e81e0ac70
1const (
2 num_iterations = 10000
3)
4
5fn do_send(ch chan int) {
6 for i in 0 .. num_iterations {
7 ch <- i
8 }
9}
10
11fn test_channel_unbuffered() {
12 ch := chan int{}
13 spawn do_send(ch)
14 mut sum := i64(0)
15 for _ in 0 .. num_iterations {
16 sum += <-ch
17 }
18 assert sum == u64(num_iterations) * (num_iterations - 1) / 2
19}