Skip to content

Instantly share code, notes, and snippets.

@dmora
Created July 19, 2018 21:34
Show Gist options
  • Save dmora/deb5cde2900ff72141a66087ac4dc15e to your computer and use it in GitHub Desktop.
Save dmora/deb5cde2900ff72141a66087ac4dc15e to your computer and use it in GitHub Desktop.
// workerPool creates or spawns new "work" goRoutines to process the "Jobs" channel
func (m *Pool) workerPool(processor ProcessorFunc) {
defer close(m.results)
log.DEBUG.Printf("Worker Pool spawning new goRoutines, total: [%d]", m.numRoutines)
var wg sync.WaitGroup
for i := 0; i < m.numRoutines; i++ {
wg.Add(1)
go m.work(&wg, processor)
log.DEBUG.Printf("Spawned work goRoutine [%d]", i)
}
log.DEBUG.Print("Worker Pool done spawning work goRoutines")
wg.Wait()
log.DEBUG.Print("all work goroutines done processing")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment