Merge branch 'master' of git.zhangdeman.cn:zhangdeman/task

This commit is contained in:
白茶清欢 2023-03-06 22:40:41 +08:00
commit 65f753208a

16
task.go
View File

@ -82,8 +82,24 @@ func (d *dispatch) Run(ctx context.Context, cfg *Config) *Result {
var (
taskInstance ITask
exist bool
cancelFunc context.CancelFunc
)
if nil == ctx {
if cfg.Timeout > 0 {
ctx, cancelFunc = context.WithCancel(context.Background())
} else {
ctx = context.Background()
}
} else {
ctx, cancelFunc = context.WithCancel(ctx)
}
if nil != cancelFunc {
// 带了超时时间
cancelFunc()
}
result := &Result{
StartTime: time.Now().UnixNano(),
FinishTime: 0,