Skip to content

Instantly share code, notes, and snippets.

@kylelemons
Created June 7, 2011 01:44
Show Gist options
  • Save kylelemons/1011514 to your computer and use it in GitHub Desktop.
Save kylelemons/1011514 to your computer and use it in GitHub Desktop.
Multiple workers in go
wg := new(sync.WaitGroup)
for i := 0; i < workers; i++ {
wg.Add(1)
go func() {
defer wg.Done()
for {
select {
case input, open := <-In:
if !open { return }
v, e := f(input)
Out <- Result{v, e}
case <-quit:
return
}
}
}()
}
work <- blah
...
close(work)
wg.Wait()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment