// A struct with a []byte crosses a spawn boundary in both directions, and the // parent joins on the domain's breaker. Runs on every target: natively the // values travel the mmap ring, on wasm the SAB ring behind the Worker boundary // (the breaker handle is created by the parent and threaded into the child's // entry, so `<-done` returns when the child exits). package main type Msg struct { N int32 Body []byte } func worker(in chan Msg, out chan int32) (closed chan struct{}) { select { case <-closed: return closed default: } for i := 0; i < 2; i++ { select { case <-closed: return closed case m := <-in: out <- m.N + int32(len(m.Body)) } } return closed } func main() { select { case <-shutdown: return default: } in := chan Msg{:2} out := chan int32{:2} done := spawn(worker, in, out) in <- Msg{N: 7, Body: []byte("hello")} in <- Msg{N: 9, Body: []byte("world")} a := <-out b := <-out <-done if a != 12 || b != 14 { panic("spawn struct values wrong") } println("spawn struct ok", a, b) }