func main() { add := worker.New(addResponseTube, add, nil) add.Run() defer func() { f := make(chan struct{}) add.Shutdown(f) <-f }() a := &addData{ A: 2, B: 2, } resp, err := worker.Send(addResponseTube, a, true, nil) if err != nil { log.Println("err:", err) return } var data int err = json.Unmarshal(resp, &data) if err != nil { log.Println("err:", err) return } log.Println("2 + 2 =", data) }
// Typically, the Run and Send functions would not be called // from the same process, but, for ease of demonstration, they // are combined for this example. func main() { // define and run a worker add := worker.New(addTube, add, nil) add.Run() // shutdown the worker on exit defer func() { f := make(chan struct{}) add.Shutdown(f) <-f }() // create a unit of work a := addData{ A: 2, B: 2, } // send it to our worker _, err := worker.Send(addTube, a, false, nil) if err != nil { log.Println("err:", err) } }