Update linter

This commit is contained in:
Ludovic Fernandez 2020-05-11 12:06:07 +02:00 committed by GitHub
parent f12c27aa7c
commit 328611c619
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
157 changed files with 489 additions and 508 deletions

View file

@ -12,14 +12,14 @@ import (
type routineCtx func(ctx context.Context)
// Pool is a pool of go routines
// Pool is a pool of go routines.
type Pool struct {
waitGroup sync.WaitGroup
ctx context.Context
cancel context.CancelFunc
}
// NewPool creates a Pool
// NewPool creates a Pool.
func NewPool(parentCtx context.Context) *Pool {
ctx, cancel := context.WithCancel(parentCtx)
return &Pool{
@ -28,7 +28,7 @@ func NewPool(parentCtx context.Context) *Pool {
}
}
// GoCtx starts a recoverable goroutine with a context
// GoCtx starts a recoverable goroutine with a context.
func (p *Pool) GoCtx(goroutine routineCtx) {
p.waitGroup.Add(1)
Go(func() {
@ -37,18 +37,18 @@ func (p *Pool) GoCtx(goroutine routineCtx) {
})
}
// Stop stops all started routines, waiting for their termination
// Stop stops all started routines, waiting for their termination.
func (p *Pool) Stop() {
p.cancel()
p.waitGroup.Wait()
}
// Go starts a recoverable goroutine
// Go starts a recoverable goroutine.
func Go(goroutine func()) {
GoWithRecover(goroutine, defaultRecoverGoroutine)
}
// GoWithRecover starts a recoverable goroutine using given customRecover() function
// GoWithRecover starts a recoverable goroutine using given customRecover() function.
func GoWithRecover(goroutine func(), customRecover func(err interface{})) {
go func() {
defer func() {
@ -66,13 +66,13 @@ func defaultRecoverGoroutine(err interface{}) {
logger.Errorf("Stack: %s", debug.Stack())
}
// OperationWithRecover wrap a backoff operation in a Recover
// OperationWithRecover wrap a backoff operation in a Recover.
func OperationWithRecover(operation backoff.Operation) backoff.Operation {
return func() (err error) {
defer func() {
if res := recover(); res != nil {
defaultRecoverGoroutine(res)
err = fmt.Errorf("panic in operation: %s", err)
err = fmt.Errorf("panic in operation: %w", err)
}
}()
return operation()