gopkg
gopkg copied to clipboard
how to pass variable to gopool function?
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)
}