mirror of
https://github.com/ceph/ceph-csi.git
synced 2024-10-19 05:39:51 +00:00
91774fc936
Uses github.com/libopenstorage/secrets to communicate with Vault. This removes the need for maintaining our own limited Vault APIs. By adding the new dependency, several other packages got updated in the process. Unused indirect dependencies have been removed from go.mod. Signed-off-by: Niels de Vos <ndevos@redhat.com>
39 lines
759 B
Go
39 lines
759 B
Go
package multierror
|
|
|
|
import "sync"
|
|
|
|
// Group is a collection of goroutines which return errors that need to be
|
|
// coalesced.
|
|
type Group struct {
|
|
mutex sync.Mutex
|
|
err *Error
|
|
wg sync.WaitGroup
|
|
}
|
|
|
|
// Go calls the given function in a new goroutine.
|
|
//
|
|
// If the function returns an error it is added to the group multierror which
|
|
// is returned by Wait.
|
|
func (g *Group) Go(f func() error) {
|
|
g.wg.Add(1)
|
|
|
|
go func() {
|
|
defer g.wg.Done()
|
|
|
|
if err := f(); err != nil {
|
|
g.mutex.Lock()
|
|
g.err = Append(g.err, err)
|
|
g.mutex.Unlock()
|
|
}
|
|
}()
|
|
}
|
|
|
|
// Wait blocks until all function calls from the Go method have returned, then
|
|
// returns the multierror.
|
|
func (g *Group) Wait() *Error {
|
|
g.wg.Wait()
|
|
g.mutex.Lock()
|
|
defer g.mutex.Unlock()
|
|
return g.err
|
|
}
|