diff --git a/sync/routinepool/pool.go b/sync/routinepool/pool.go index fd7349c..cc440d8 100644 --- a/sync/routinepool/pool.go +++ b/sync/routinepool/pool.go @@ -2,6 +2,7 @@ package routinepool import ( "context" + "log" "sync" "sync/atomic" ) @@ -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 } diff --git a/sync/routinepool/worker.go b/sync/routinepool/worker.go index 79b5944..3e4cfd1 100644 --- a/sync/routinepool/worker.go +++ b/sync/routinepool/worker.go @@ -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: