Skip to content

Instantly share code, notes, and snippets.

@RobAWilkinson
Last active October 16, 2017 17:09
Show Gist options
  • Save RobAWilkinson/c0e960f856d092b7c58430ff81d45158 to your computer and use it in GitHub Desktop.
Save RobAWilkinson/c0e960f856d092b7c58430ff81d45158 to your computer and use it in GitHub Desktop.
// question for you is there a difference between,
var records [][]string
var wg sync.WaitGroup
for _, r := range records {
wg.Add(1)
go func(record []string) {
host, desc := record[0], record[1]
defer wg.Done()
fmt.Println(host)
fmt.Println(desc)
// do something with that data
}(r)
}
// or this style
for _, r := range records {
host, desc := r[0], r[1]
wg.Add(1)
go func() {
defer wg.Done()
// do something with host, desc
fmt.Println(host)
fmt.Println(desc)
}()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment