make sure workers are done when closing via a WaitGroup

still running out of goroutines in race tests in CI, so hopefully this
fixes that.
This commit is contained in:
Matt Jaffee 2019-07-15 08:36:22 -05:00
parent 7d7a5539ca
commit a7d9b0a5ae
No known key found for this signature in database
GPG key ID: 08A3DFFF987B11BF

View file

@ -20,6 +20,7 @@ import (
"fmt"
"runtime"
"sort"
"sync"
"time"
"github.com/pilosa/pilosa/pql"
@ -57,7 +58,8 @@ type executor struct {
// Stores key/id translation data.
TranslateStore TranslateStore
work chan job
workersWG sync.WaitGroup
work chan job
}
// executorOption is a functional option type for pilosa.Executor
@ -88,13 +90,18 @@ func newExecutor(opts ...executorOption) *executor {
}
}
for i := 0; i < workerPoolSize; i++ {
go worker(e.work)
e.workersWG.Add(1)
go func() {
defer e.workersWG.Done()
worker(e.work)
}()
}
return e
}
func (e *executor) Close() error {
close(e.work)
e.workersWG.Wait()
return nil
}