2021-01-06 23:19:40 +03:00
|
|
|
const n = 1000
|
|
|
|
|
2021-01-09 04:43:48 +03:00
|
|
|
fn f(ch chan f64) {
|
|
|
|
mut s := 0.
|
2021-01-06 23:19:40 +03:00
|
|
|
for _ in 0 .. n {
|
|
|
|
s += <-ch
|
|
|
|
}
|
2021-01-09 04:43:48 +03:00
|
|
|
assert s == f64(n * (n + 1) / 2)
|
2021-01-06 23:19:40 +03:00
|
|
|
ch.close()
|
|
|
|
}
|
|
|
|
|
2021-01-09 04:43:48 +03:00
|
|
|
fn do_send(ch chan f64, val f64) ?f64 {
|
2021-01-06 23:19:40 +03:00
|
|
|
ch <- val ?
|
2021-01-09 04:43:48 +03:00
|
|
|
return val + 1.0
|
2021-01-06 23:19:40 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
fn test_push_propargate() {
|
2021-01-09 04:43:48 +03:00
|
|
|
ch := chan f64{}
|
2021-01-06 23:19:40 +03:00
|
|
|
go f(ch)
|
2021-01-09 04:43:48 +03:00
|
|
|
mut s := 1.0
|
2021-01-06 23:19:40 +03:00
|
|
|
for {
|
2021-05-08 13:32:29 +03:00
|
|
|
s = do_send(ch, s) or { break }
|
2021-01-06 23:19:40 +03:00
|
|
|
}
|
2021-01-09 04:43:48 +03:00
|
|
|
assert s == f64(n + 1)
|
2021-01-06 23:19:40 +03:00
|
|
|
}
|