Fork-Join

(aka Scatter/Gather)

Bunch of items to process

Idempotent work; can be done concurrently

// we're going to work on up to NumCPU items at once
for i := 0; i < runtime.NumCPU(); i++ {
go func() {
// see how easy it is to iterate a channel?
for job := range jobs {
results <- ProcessJob(job)
}
}()
}

// load all work into the input channel
for _, spec := range work {
jobs <- spec
}
// indicate when to shutdown by closing channel
close(jobs)

// now iterate each work item and handle the result
for i := 0; i < len(work); i++ {
result := <-results
// handle result here...
}
}