1 | const n = 1000 |
2 | |
3 | fn f(ch chan f64) { |
4 | mut s := 0.0 |
5 | for _ in 0 .. n { |
6 | s += <-ch |
7 | } |
8 | assert s == f64(n * (n + 1) / 2) |
9 | ch.close() |
10 | } |
11 | |
12 | fn do_send(ch chan f64, val f64) ?f64 { |
13 | ch <- val? |
14 | return val + 1.0 |
15 | } |
16 | |
17 | fn test_push_propargate() { |
18 | ch := chan f64{} |
19 | spawn f(ch) |
20 | mut s := 1.0 |
21 | for { |
22 | s = do_send(ch, s) or { break } |
23 | } |
24 | assert s == f64(n + 1) |
25 | } |