喵喵时光机
你的意思是这样吗?package mainimport "fmt"func ping(recv <-chan int, send chan<- int, end chan<- bool) { fmt.Println("ping") send <- 11 send <- 12 r1 := <-recv r2 := <-recv fmt.Println("ping", r1, r2) end <- true}func pong(recv <-chan int, send chan<- int, end chan<- bool) { fmt.Println("pong") r1 := <-recv r2 := <-recv send <- 21 send <- 22 fmt.Println("pong", r1, r2) end <- true}func main() { chEnd := make(chan bool) chPing := make(chan int, 2) chPong := make(chan int, 2) go ping(chPing, chPong, chEnd) go pong(chPong, chPing, chEnd) <-chEnd <-chEnd fmt.Println("end")}输出:pingpongpong 11 12ping 21 22end