2020-08-06 16:28:19 +03:00
|
|
|
const (
|
|
|
|
num_iterations = 10000
|
|
|
|
)
|
|
|
|
|
2020-08-31 11:44:39 +03:00
|
|
|
fn do_send(ch chan int) {
|
2020-08-06 16:28:19 +03:00
|
|
|
for i in 0 .. num_iterations {
|
2020-08-31 11:44:39 +03:00
|
|
|
ch <- i
|
2020-08-06 16:28:19 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn test_channel_unbuffered() {
|
2020-08-31 11:44:39 +03:00
|
|
|
ch := chan int{}
|
2022-11-05 10:46:40 +03:00
|
|
|
spawn do_send(ch)
|
2020-08-06 16:28:19 +03:00
|
|
|
mut sum := i64(0)
|
|
|
|
for _ in 0 .. num_iterations {
|
2020-08-31 11:44:39 +03:00
|
|
|
sum += <-ch
|
2020-08-06 16:28:19 +03:00
|
|
|
}
|
2021-05-08 13:32:29 +03:00
|
|
|
assert sum == u64(num_iterations) * (num_iterations - 1) / 2
|
2020-08-06 16:28:19 +03:00
|
|
|
}
|