Update linter
This commit is contained in:
parent
f12c27aa7c
commit
328611c619
157 changed files with 489 additions and 508 deletions
|
@ -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()
|
||||
|
|
|
@ -4,25 +4,25 @@ import (
|
|||
"sync"
|
||||
)
|
||||
|
||||
// Safe contains a thread-safe value
|
||||
// Safe contains a thread-safe value.
|
||||
type Safe struct {
|
||||
value interface{}
|
||||
lock sync.RWMutex
|
||||
}
|
||||
|
||||
// New create a new Safe instance given a value
|
||||
// New create a new Safe instance given a value.
|
||||
func New(value interface{}) *Safe {
|
||||
return &Safe{value: value, lock: sync.RWMutex{}}
|
||||
}
|
||||
|
||||
// Get returns the value
|
||||
// Get returns the value.
|
||||
func (s *Safe) Get() interface{} {
|
||||
s.lock.RLock()
|
||||
defer s.lock.RUnlock()
|
||||
return s.value
|
||||
}
|
||||
|
||||
// Set sets a new value
|
||||
// Set sets a new value.
|
||||
func (s *Safe) Set(value interface{}) {
|
||||
s.lock.Lock()
|
||||
defer s.lock.Unlock()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue