v / vlib / sync
Raw file | 25 loc (22 sloc) | 400 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_buffered() {
12 ch := chan int{cap: 1000}
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}
20
21fn test_builtin_enum() {
22 x := ChanState.closed
23 assert x == .closed
24 println(x)
25}