1 package lib
2 3 // Msg crosses a spawn boundary from main: a named struct in ANOTHER package
4 // whose only variable-length field is a []byte. It is offset-frame eligible,
5 // so its frame is built by lib's type descriptor on the receiving side and by
6 // main's on the sending side - the cross-package case for the sizer and the
7 // codec.
8 type Msg struct {
9 N int32
10 Body []byte
11 }
12 13 // Worker is a spawn target in a library package.
14 func Worker(in chan Msg, out chan int32) (closed chan struct{}) {
15 select {
16 case <-closed:
17 return closed
18 default:
19 }
20 for i := 0; i < 2; i++ {
21 select {
22 case <-closed:
23 return closed
24 case m := <-in:
25 out <- m.N + int32(len(m.Body))
26 }
27 }
28 return closed
29 }
30