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

how to pass variable to gopool function? #143

Open
hiqsociety opened this issue Jun 28, 2022 · 1 comment
Open

how to pass variable to gopool function? #143

hiqsociety opened this issue Jun 28, 2022 · 1 comment
Labels
question Further information is requested

Comments

@hiqsociety
Copy link

Question

go something(str string) {
}(str)

how to do the equivalent in gopool?

@hiqsociety hiqsociety added the question Further information is requested label Jun 28, 2022
@Zhenghao-Liu
Copy link

  • like this
func main() {
	for i := 0; i < 100; i++ {
		func(i int) {
			gopool.Go(func() {
				fmt.Printf("%d\t", i)
			})
		}(i)
	}
        time.Sleep(5 * time.Second)
}
  • but not like this
func main() {
	for i := 0; i < 20; i++ {
		gopool.Go(func() {
			fmt.Printf("%d\t", i)
		})
	}
	time.Sleep(5 * time.Second)
}

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

No branches or pull requests

2 participants