1 //:wasmtest skip
2 // Native-only: the wasm target requires a spawn target to be in the same
3 // package as the caller, and this fixture's Worker lives in lib. The
4 // same-package wasm coverage is wasm_spawn_struct.mx.
5 // A struct with a []byte crosses a spawn channel whose target lives in another
6 // package. The element is offset-frame eligible; both sides build and decode
7 // the frame from lib.Msg's descriptor, so this covers the cross-package
8 // descriptor, the sizer and the codec in one program. Native and wasm: the
9 // worker reports through a channel, so the main domain does all the printing.
10 package main
11 12 import (
13 "tests/regressions/should_compile/spawn_crosspkg_struct/lib"
14 )
15 16 func main() {
17 select {
18 case <-shutdown:
19 return
20 default:
21 }
22 in := chan lib.Msg{:2}
23 out := chan int32{:2}
24 done := spawn(lib.Worker, in, out)
25 in <- lib.Msg{N: 7, Body: []byte("hello")}
26 in <- lib.Msg{N: 9, Body: []byte("world")}
27 a := <-out
28 b := <-out
29 <-done
30 if a != 12 || b != 14 {
31 panic("cross-package spawn values wrong")
32 }
33 println("crosspkg spawn ok", a, b)
34 }
35