Skip to content

Commit

Permalink
feat(携程池[routinePool]): 携程池错误处理
Browse files Browse the repository at this point in the history
  • Loading branch information
Ccheers committed Jul 1, 2022
1 parent c1631f3 commit 365505a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
4 changes: 4 additions & 0 deletions sync/routinepool/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package routinepool

import (
"context"
"log"
"sync"
"sync/atomic"
)
Expand Down Expand Up @@ -83,6 +84,9 @@ func NewPool(name string, cap int32, config *Config) Pool {
cap: cap,
config: config,
}
p.SetPanicHandler(func(ctx context.Context, err error) {
log.Println(err.Error())
})
return p
}

Expand Down
4 changes: 3 additions & 1 deletion sync/routinepool/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ func (w *worker) run() {
// check context before doing task
select {
case <-t.ctx.Done():
w.pool.panicHandler(t.ctx, fmt.Errorf("[routinepool] task cancel: %s error: %w", w.pool.name, t.ctx.Err()))
if w.pool.panicHandler != nil {
w.pool.panicHandler(t.ctx, fmt.Errorf("[routinepool] task cancel: %s error: %w", w.pool.name, t.ctx.Err()))
}
t.Recycle()
continue
default:
Expand Down

0 comments on commit 365505a

Please sign in to comment.