Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Work will only take as long as slowest process
// Scatter
c := make(chan result, 10)
for i := 0; i < cap(c); i++ {
go func() {
val, err := process()
c <- result{val, err}
}()
}
// Gather
var total int
for i := 0; i < cap(c); i++ {
res := <-c
if res.err != nil {
total += res.val
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment