main.go raw
1 package main
2
3 import "moxie"
4
5 // B.0.1 test: select on pipe-bound channels.
6 // Parent uses select to multiplex between two pipe-bound channels
7 // (one receives results, one is the timeout/control signal). Verifies:
8 // - tryRecv path on pipe-bound channels works
9 // - blocking poll loop wakes when pipe data arrives
10 // - mixed-readiness case (one channel ready, one not)
11
12 func producer(out chan moxie.Int32, ctrl chan moxie.Int32) {
13 for i := int32(0); i < 5; i++ {
14 out <- moxie.Int32(i)
15 }
16 ctrl <- moxie.Int32(99)
17 }
18
19 func main() {
20 out := make(chan moxie.Int32)
21 ctrl := make(chan moxie.Int32)
22 spawn(producer, out, ctrl)
23
24 count := int32(0)
25 sum := int32(0)
26 done := false
27 for !done {
28 select {
29 case v := <-out:
30 count++
31 sum += int32(v)
32 case c := <-ctrl:
33 if int32(c) != 99 {
34 println("FAIL:select", "wrong ctrl value", int32(c))
35 return
36 }
37 done = true
38 }
39 }
40
41 if count != 5 || sum != 0+1+2+3+4 {
42 println("FAIL:select", "count", count, "sum", sum)
43 return
44 }
45 println("PASS:select-pipe-bound")
46 }
47