 Chromium Code Reviews
 Chromium Code Reviews Issue 2958433002:
  [errors] Remove Fix(), move MultiErrorFromErrors().  (Closed)
    
  
    Issue 2958433002:
  [errors] Remove Fix(), move MultiErrorFromErrors().  (Closed) 
  | Index: common/sync/parallel/workPool.go | 
| diff --git a/common/sync/parallel/workPool.go b/common/sync/parallel/workPool.go | 
| index b1592b068271eff2168e0954e1d5c28f9d456281..b552c5c876a66619b4ad117f169fca9efdda39d6 100644 | 
| --- a/common/sync/parallel/workPool.go | 
| +++ b/common/sync/parallel/workPool.go | 
| @@ -17,7 +17,7 @@ import ( | 
| // WorkPool blocks until all the generator completes and all workers have | 
| // finished their tasks. | 
| func WorkPool(workers int, gen func(chan<- func() error)) error { | 
| - return errors.MultiErrorFromErrors(Run(workers, gen)) | 
| + return MultiErrorFromErrors(Run(workers, gen)) | 
| } | 
| // FanOutIn is useful to quickly parallelize a group of tasks. | 
| @@ -34,3 +34,23 @@ func WorkPool(workers int, gen func(chan<- func() error)) error { | 
| func FanOutIn(gen func(chan<- func() error)) error { | 
| return WorkPool(0, gen) | 
| } | 
| + | 
| +// MultiErrorFromErrors takes an error-channel, blocks on it, and returns | 
| +// a MultiError for any errors pushed to it over the channel, or nil if | 
| +// all the errors were nil. | 
| +func MultiErrorFromErrors(ch <-chan error) error { | 
| 
Vadim Sh.
2017/06/23 00:32:16
does it have to be public? Anyone uses it besides
 | 
| + if ch == nil { | 
| + return nil | 
| + } | 
| + ret := errors.MultiError(nil) | 
| + for e := range ch { | 
| + if e == nil { | 
| + continue | 
| + } | 
| + ret = append(ret, e) | 
| + } | 
| + if len(ret) == 0 { | 
| + return nil | 
| + } | 
| + return ret | 
| +} |