bytedance / gopkg

Universal Utilities for Go

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

how to pass variable to gopool function?

hiqsociety opened this issue · comments

Question

go something(str string) {
}(str)

how to do the equivalent in gopool?

  • 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)
}