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