We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
return
case <-quit:
func spawn(f func(int)) chan string { quit := make(chan string) go func() { var job chan int // 模拟job channel for { select { case j := <-job: f(j) case <-quit: quit <- "ok" + return } } }() return quit }
The text was updated successfully, but these errors were encountered:
这个不是好不好理解的问题,这个就是问题,就应该有一个return,当worker goroutine收到quit通知后,就应该马上退出。感谢指出问题。该问题将更新到勘误表。
Sorry, something went wrong.
dc09f67
var job chan int // 模拟job channel 这个可以稍微多说两句吗, 或者具体化一下. 因为本质应该是来调度worker函数的 没理解这个job chan的实际意义.
var job chan int // 模拟job channel
No branches or pull requests
return
是否更好理解呢?case <-quit:
分支完成后,在 main goroutine 没结束前 for 循环还会继续,worker 可能还会再工作func spawn(f func(int)) chan string { quit := make(chan string) go func() { var job chan int // 模拟job channel for { select { case j := <-job: f(j) case <-quit: quit <- "ok" + return } } }() return quit }
The text was updated successfully, but these errors were encountered: