Skip to content

Instantly share code, notes, and snippets.

@dumindu
Last active April 9, 2023 07:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dumindu/80a9e888d55afdf7a1d0f75566f41589 to your computer and use it in GitHub Desktop.
Save dumindu/80a9e888d55afdf7a1d0f75566f41589 to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"sync"
)
func main() {
items := []int{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}
wg := sync.WaitGroup{}
wg.Add(len(items))
for _, item := range items {
go func(i int) {
fmt.Println(i)
wg.Done()
}(item)
}
wg.Wait()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment