v2 / vlib / v / tests / generics / generic_chan_test.v
22 lines · 20 sloc · 379 bytes · 6488041a749df9762348d019c4223908c476f2e2
Raw
1fn mk_chan[T](f fn () T) chan T {
2 gench := chan T{cap: 1}
3 // // This does not work, yet
4 // go fn(ch2 chan T, f2 fn() T) {
5 // res := f2()
6 // ch2 <- res
7 // }(gench, f)
8 return gench
9}
10
11fn g(x f64, y f64) f64 {
12 return x * x + y * y
13}
14
15fn test_generic_chan_return() {
16 ch := mk_chan[f64](fn () f64 {
17 return g(3, 4)
18 })
19 ch <- 13.4
20 res := <-ch
21 assert res == 13.4
22}
23