Multiplexing server (from GoCourseDay3
type request struct {
a, b int;
replyc chan int;
}
type binOp func(a, b int) int
func run(op binOp, req *request) {
req.replyc <- op(req.a, req.b)
}
func server(op binOp, service chan *request) {
for {
req := <-service; // requests arrive here
go run(op, req); // don't wait for op
}
}