package
0.0.0-20240430070110-32c8d490bf49
Repository: https://github.com/eachain/common.git
Documentation: pkg.go.dev
# Packages
No description provided by the author
# Functions
CtxDone 将<-ctx.Done()的判断以bool返回,
用于在for循环里面判断退出条件。
for !CtxDone(ctx) {
..
Go 用于协程管理,可以用于后台协连接池管理等。
Go("biz_name", func(ctx context.Context) {
for !CtxDone(ctx) {
..
No description provided by the author
No description provided by the author
Retry用于出错重试,等待时间从50ms一直倍增,最大到10s。
比如:
var ctx = context.Background()
var conn net.Conn
var err error
err = Retry(ctx, func() error {
conn, err = (&net.Dialer{}).DialContext(ctx, "tcp", "www.baidu.com:443")
return err
}, 5)
if err != nil {
..
StopAndWait 用于停掉所有biz的协程,并等待退出。biz必须和Go(biz, fn)里面的biz一致。
Go和StopAndWait经常被用于各种自治组件,比如连接池、任务池等管理。
例如:
type Pool struct {
biz string
..
# Variables
No description provided by the author
# Structs
No description provided by the author
No description provided by the author
No description provided by the author
# Interfaces
No description provided by the author
# Type aliases
TypeConverter 是一个类型转换工具.