Download common/gopool.go from AZILS/new-api: direct link, hf CLI and curl.
- Browser
- Download file 540 Bytes
-
https://huggingface.co/spaces/AZILS/new-api/resolve/main/common/gopool.go
- Command line
-
hf download hf://spaces/AZILS/new-api/common/gopool.go
-
curl -L -o gopool.go https://huggingface.co/spaces/AZILS/new-api/resolve/main/common/gopool.go
540 Bytes
| package common | |
| import ( | |
| "context" | |
| "fmt" | |
| "math" | |
| "github.com/bytedance/gopkg/util/gopool" | |
| ) | |
| var relayGoPool gopool.Pool | |
| func init() { | |
| relayGoPool = gopool.NewPool("gopool.RelayPool", math.MaxInt32, gopool.NewConfig()) | |
| relayGoPool.SetPanicHandler(func(ctx context.Context, i interface{}) { | |
| if stopChan, ok := ctx.Value("stop_chan").(chan bool); ok { | |
| SafeSendBool(stopChan, true) | |
| } | |
| SysError(fmt.Sprintf("panic in gopool.RelayPool: %v", i)) | |
| }) | |
| } | |
| func RelayCtxGo(ctx context.Context, f func()) { | |
| relayGoPool.CtxGo(ctx, f) | |
| } | |