2013-01-25 02:34:11 +04:00
|
|
|
package mysqlctl
|
|
|
|
|
|
|
|
import (
|
Automatic rewrite of relog import paths and calls to use glog.
Commands run:
find go -name "*.go" | xargs sed --in-place -r 's,"github.com/youtube/vitess/go/relog",log "github.com/golang/glog",g; s,relog.Info,log.Infof,g; s,relog.Warning,log.Warningf,g; s,relog.Error,log.Errorf,g; s,relog.Fatal,log.Fatalf,g; s,relog.Debug,log.V(6).Infof,g'
find . -name '*.go' -exec gofmt -w {} \;
2013-08-07 01:56:00 +04:00
|
|
|
log "github.com/golang/glog"
|
2013-01-25 02:34:11 +04:00
|
|
|
)
|
|
|
|
|
2013-02-15 05:25:03 +04:00
|
|
|
type MapFunc func(index int) error
|
2013-01-25 02:34:11 +04:00
|
|
|
|
2013-02-15 05:25:03 +04:00
|
|
|
// ConcurrentMap applies fun in a concurrent manner on integers from 0
|
|
|
|
// to n-1 (they are assumed to be indexes of some slice containing
|
|
|
|
// items to be processed). The first error returned by a fun
|
|
|
|
// application will returned (subsequent errors will only be
|
|
|
|
// logged). It will use concurrency goroutines.
|
|
|
|
func ConcurrentMap(concurrency, n int, fun MapFunc) error {
|
2013-01-25 02:34:11 +04:00
|
|
|
errors := make(chan error)
|
|
|
|
work := make(chan int, n)
|
|
|
|
|
|
|
|
for i := 0; i < n; i++ {
|
|
|
|
work <- i
|
|
|
|
}
|
|
|
|
close(work)
|
|
|
|
|
|
|
|
for j := 0; j < concurrency; j++ {
|
|
|
|
go func() {
|
|
|
|
for i := range work {
|
2013-02-15 05:25:03 +04:00
|
|
|
errors <- fun(i)
|
2013-01-25 02:34:11 +04:00
|
|
|
}
|
|
|
|
}()
|
|
|
|
}
|
|
|
|
var err error
|
|
|
|
|
|
|
|
for i := 0; i < n; i++ {
|
|
|
|
if e := <-errors; e != nil {
|
|
|
|
if err != nil {
|
Automatic rewrite of relog import paths and calls to use glog.
Commands run:
find go -name "*.go" | xargs sed --in-place -r 's,"github.com/youtube/vitess/go/relog",log "github.com/golang/glog",g; s,relog.Info,log.Infof,g; s,relog.Warning,log.Warningf,g; s,relog.Error,log.Errorf,g; s,relog.Fatal,log.Fatalf,g; s,relog.Debug,log.V(6).Infof,g'
find . -name '*.go' -exec gofmt -w {} \;
2013-08-07 01:56:00 +04:00
|
|
|
log.Errorf("multiple errors, this one happened but it won't be returned: %v", err)
|
2013-01-25 02:34:11 +04:00
|
|
|
}
|
|
|
|
err = e
|
|
|
|
}
|
|
|
|
}
|
2013-02-15 05:25:03 +04:00
|
|
|
return err
|
2013-01-25 02:34:11 +04:00
|
|
|
}
|