aboutsummaryrefslogtreecommitdiff
path: root/v_windows/v/old/vlib/sync/channel_2_test.v
blob: 5e8251d862e6b10f5c59529b9d9742dbc0b55052 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
const (
	num_iterations = 10000
)

fn do_send(ch chan int) {
	for i in 0 .. num_iterations {
		ch <- i
	}
}

fn test_channel_unbuffered() {
	ch := chan int{}
	go do_send(ch)
	mut sum := i64(0)
	for _ in 0 .. num_iterations {
		sum += <-ch
	}
	assert sum == u64(num_iterations) * (num_iterations - 1) / 2
}