in unison/safewaitgroup.go [81:99]
func (s *SafeWaitGroup) Close() {
// When the context is cancelled, either by the parent context or by calling
// 'cancel' directly, Close will be called.
// The `cancel` function must always be called in order to clean up the context resources.
// Due to `cancel` calling `Close`, we better be sure to have the mutex
// released before calling cancel.
// Although `cancel` is likely to be run in another go-routine, we don't want
// to make any assumptions about implementation details of the context and cancel function.
var wasClosed bool
func() {
s.mu.Lock()
defer s.mu.Unlock()
wasClosed, s.closed = s.closed, true
}()
if !wasClosed && s.cancel != nil {
s.cancel()
}
}