Skip to content
New issue

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

chapter6/sources/go-concurrency-pattern-5.go #28

Closed
osxtest opened this issue Aug 27, 2022 · 3 comments
Closed

chapter6/sources/go-concurrency-pattern-5.go #28

osxtest opened this issue Aug 27, 2022 · 3 comments

Comments

@osxtest
Copy link

osxtest commented Aug 27, 2022

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
}
@bigwhite
Copy link
Owner

bigwhite commented Sep 3, 2022

这个不是好不好理解的问题,这个就是问题,就应该有一个return,当worker goroutine收到quit通知后,就应该马上退出。感谢指出问题。该问题将更新到勘误表。

1 similar comment
@bigwhite
Copy link
Owner

bigwhite commented Sep 3, 2022

这个不是好不好理解的问题,这个就是问题,就应该有一个return,当worker goroutine收到quit通知后,就应该马上退出。感谢指出问题。该问题将更新到勘误表。

@txjjjjj
Copy link

txjjjjj commented Feb 7, 2023

var job chan int // 模拟job channel 这个可以稍微多说两句吗, 或者具体化一下. 因为本质应该是来调度worker函数的
没理解这个job chan的实际意义.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants