深入学习golang — channel
goroutine。同样,我们也可以通过channel将处理结果返回给主goroutine。 主goroutine: type Request struct { args []int resultChan chan int } request := &Request{[]int{3, 4, 5}, make(chan int)} // Send request clientRequests <- request // Wait for response. fmt.Printf("answer: %d\n", <-request.resultChan) 主goroutine将请求发给request channel,然后等待result channel。子goroutine完成处理后,将结果写到result...阅读全文