添加超时时间的限制

This commit is contained in:
Yun
2024-06-22 15:34:49 +08:00
parent 5ca5b31efb
commit 79fda8c78c
2 changed files with 19 additions and 5 deletions
+13 -4
View File
@@ -3,14 +3,16 @@ package timerx
import "time"
type Options struct {
logger Logger
location *time.Location
logger Logger
location *time.Location
timeout time.Duration
}
func defaultOptions() Options {
return Options{
logger: NewLogger(),
location: time.Local,
logger: NewLogger(),
location: time.Local,
timeout: time.Hour,
}
}
@@ -37,3 +39,10 @@ func SetTimeZone(zone *time.Location) Option {
o.location = zone
}
}
// 设置任务最长执行时间
func SetTimeout(d time.Duration) Option {
return func(o *Options) {
o.timeout = d
}
}