gopool.go 539 B

123456789101112131415161718192021222324
  1. package common
  2. import (
  3. "context"
  4. "fmt"
  5. "github.com/bytedance/gopkg/util/gopool"
  6. "math"
  7. )
  8. var relayGoPool gopool.Pool
  9. func init() {
  10. relayGoPool = gopool.NewPool("gopool.RelayPool", math.MaxInt32, gopool.NewConfig())
  11. relayGoPool.SetPanicHandler(func(ctx context.Context, i interface{}) {
  12. if stopChan, ok := ctx.Value("stop_chan").(chan bool); ok {
  13. SafeSendBool(stopChan, true)
  14. }
  15. SysError(fmt.Sprintf("panic in gopool.RelayPool: %v", i))
  16. })
  17. }
  18. func RelayCtxGo(ctx context.Context, f func()) {
  19. relayGoPool.CtxGo(ctx, f)
  20. }