reject_edge_copy.mx raw

   1  // An Edge has one owner (docs/memory-model.md section 4, D19 rule 4): it moves
   2  // to one spawn, or out of a function as a return value, and any other use copies
   3  // the pair. A copy would give two owners the same handles.
   4  //
   5  // expected: an Edge cannot be copied
   6  package main
   7  
   8  type Req struct {
   9  	Body []byte `cap:"1024"`
  10  }
  11  
  12  func worker(ep Edge[Req, int32]) (closed chan struct{}) {
  13  	for {
  14  		select {
  15  		case <-closed:
  16  			return closed
  17  		case r := <-ep.Recv:
  18  			_ = r
  19  		}
  20  	}
  21  }
  22  
  23  func main() {
  24  	select {
  25  	case <-shutdown:
  26  		return
  27  	default:
  28  	}
  29  	parent, child := edge[int32, Req]{2}
  30  	dup := child
  31  	_ = dup
  32  	done := spawn(worker, child)
  33  	close(parent.Send)
  34  	<-done
  35  }
  36