Skip to content

Instantly share code, notes, and snippets.

@pot-code
Last active April 9, 2020 13:15
Show Gist options
  • Save pot-code/9b748eda0e42688d0502765ed867774d to your computer and use it in GitHub Desktop.
Save pot-code/9b748eda0e42688d0502765ed867774d to your computer and use it in GitHub Desktop.
[goroutine] snippet
func worker(queue chan string, signal *sync.WaitGroup) {
for work := range queue {
}
signal.Done()
}
func main() {
count := runtime.NumCPU() - 1
queue := make(chan string, 10)
signal := new(sync.WaitGroup)
signal.Add(count)
for i := 0; i < count; i++ {
go worker(queue, signal)
}
//
// fill queue
//
close(queue)
signal.Wait()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment