Documentation
¶
Index ¶
- Variables
- func Delegate(c context.Context, t time.Duration, f func(ctx context.Context) error) error
- func SetCheckTime(d time.Duration) options.Option
- func SetIdle(idle int64) options.Option
- func SetLogger(logger log.Logger) options.Option
- func SetMax(max int64) options.Option
- func SetStopTimeout(d time.Duration) options.Option
- type GGroup
- type Goroutine
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ErrRepeatClose = errors.New("goroutine/goroutine :重复关闭")
Functions ¶
Types ¶
type GGroup ¶
type GGroup interface {
// ChangeMax 更改buffer大小
ChangeMax(m int64)
// AddTask 添加需要 `go function`
AddTask(f func()) bool
// AddTaskN 异步添加任务,有超时机制
AddTaskN(ctx context.Context, f func()) bool
// Shutdown 回收资源
Shutdown() error
// Trick debug
Trick() string
}
func NewGoroutine ¶
NewGoroutine 实例化方法
Example ¶
// 默认配置
// gGroup = NewGoroutine(context.TODO())
// 可供选择配置选项
// 设置停止超时时间
// SetStopTimeout(time.Second)
// 设置日志对象
// SetLogger(&testLogger{})
// 设置pool最大容量
// SetMax(100)
gGroup = NewGoroutine(context.TODO(),
SetStopTimeout(time.Second),
SetLogger(log.DefaultLogger),
SetMax(100),
)
type Goroutine ¶
type Goroutine struct {
// contains filtered or unexported fields
}
func (*Goroutine) AddTask ¶
AddTask 添加任务 直到添加成功为止
Example ¶
if !gGroup.AddTask(mockFunc()) {
// 添加任务失败
}
func (*Goroutine) AddTaskN ¶
AddTaskN 添加任务 有超时时间
Example ¶
// 带有超时控制添加任务
if !gGroup.AddTaskN(context.TODO(), mockFunc()) {
// 添加任务失败
}
Click to show internal directories.
Click to hide internal directories.