vxx2 / vlib / v / checker / tests / go_wait_or.vv
48 lines · 44 sloc · 623 bytes · 0c8ce3bcb9fd4a2e5bd5f991a5a07da976d780d7
Raw
1fn d(n int) f64 {
2 return f64(n)
3}
4
5fn e(n int) {}
6
7fn f(n int) ?f64 {
8 return f64(n)
9}
10
11fn g(n int) ? {}
12
13fn main() {
14 tg := [
15 spawn d(0),
16 spawn d(1),
17 ]
18 r := tg.wait()?
19 println(r)
20 s := tg[0].wait() or { panic('problem') }
21 println(s)
22 tg2 := [
23 spawn e(0),
24 spawn e(1),
25 ]
26 tg2.wait() or { panic('problem') }
27 tg2[0].wait()?
28 tg3 := [
29 spawn f(0),
30 spawn f(1),
31 ]
32 tg3.wait() or { panic('problem') }
33 for t in tg3 {
34 a := t.wait()
35 println(a)
36 }
37 for i, _ in tg3 {
38 a := tg3[i].wait()
39 println(a)
40 }
41 tg4 := [
42 spawn g(0),
43 spawn g(1),
44 ]
45 tg4.wait()
46 tg4[0].wait()
47 spawn g(3) or { panic('problem') }
48}
49