gopool.go 579 B

12345678910111213141516171819202122232425
  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. //check ctx.Value("stop_chan").(chan bool)
  13. if stopChan, ok := ctx.Value("stop_chan").(chan bool); ok {
  14. SafeSendBool(stopChan, true)
  15. }
  16. SysError(fmt.Sprintf("panic in gopool.RelayPool: %v", i))
  17. })
  18. }
  19. func CtxGo(ctx context.Context, f func()) {
  20. relayGoPool.CtxGo(ctx, f)
  21. }