Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
35 lines (28 sloc) 568 Bytes
package rollback
func SyncParallel(workers ...Worker) error {
var gerr error
total := len(workers)
chErr := make(chan error)
chDone := make(chan struct{})
chFinish := make(chan struct{})
chRollback := make(chan struct{})
defer func() {
for i := 0; i < total; i++ {
<-chDone
}
}()
for i := range workers {
go AsyncHandler(chErr, chDone, chFinish, chRollback, workers[i])
}
for i := 0; i < total; i++ {
if err := <-chErr; err != nil {
gerr = err
}
}
if gerr != nil {
close(chRollback)
return gerr
}
close(chFinish)
return nil
}