gofunc(){// in for-select using ok to exit goroutinefor{select{case x, ok :=<-in:if!ok {return}
fmt.Printf("Process %d\n", x)
processedCnt++case<-t.C:
fmt.Printf("Working, processedCnt = %d\n", processedCnt)}}}()
for-range 是上述ok的简化版 (优雅关闭)
gofunc(in <-chanint){// Using for-range to exit goroutine// range has the ability to detect the close/end of a channelfor x :=range in {
fmt.Printf("Process %d\n", x)}}(inCh)