1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

all: implement ch <- x or {...} and ch <- x ? (#7928)

This commit is contained in:
Uwe Krüger
2021-01-06 21:19:40 +01:00
committed by GitHub
parent 6f1416b5e3
commit ffd753abdc
7 changed files with 178 additions and 2 deletions

View File

@ -0,0 +1,27 @@
const n = 1000
fn f(ch chan int) {
mut s := 0
for _ in 0 .. n {
s += <-ch
}
assert s == n * (n + 1) / 2
ch.close()
}
fn do_send(ch chan int, val int) ?int {
ch <- val ?
return val + 1
}
fn test_push_propargate() {
ch := chan int{}
go f(ch)
mut s := 1
for {
s = do_send(ch, s) or {
break
}
}
assert s == n + 1
}