refactor(global): 将Cron.Start()改为go Cron.Run()并移除cronex.Start()方法

This commit is contained in:
1
2025-09-22 06:17:39 +00:00
parent 9a3ffe93d8
commit 6fb5a9d09d
3 changed files with 5 additions and 11 deletions

View File

@@ -40,12 +40,6 @@ func (c *Cronex) Run() {
c.Run()
}
// 异步运行消费者循环
func (c *Cronex) Start() {
//ants.Submit(c.Run)
go c.Run()
}
// 关闭cronex的任务循环
func (c *Cronex) Stop() {
c.Stop()

View File

@@ -15,7 +15,7 @@ func Test_Cronex(t *testing.T) {
}
cron := New()
cron.Start() //运行事件循环
go cron.Run()
count := 2
durationChan := make(chan time.Duration, count)
@@ -82,7 +82,7 @@ func Test_Cronex_ParseNext(t *testing.T) {
left := first + time.Duration(0.8*float64(time.Second))
right := first + time.Duration(1.2*float64(time.Second))
tv := now.Sub(time.Now())
tv := time.Until(now)
if tv < left || tv > right {
t.Logf("tv(%v), tv < left(%v) || tv > right(%v)", tv, left, right)
return
@@ -95,7 +95,7 @@ func Test_Multiple(t *testing.T) {
cron := New()
count := int32(0)
cron.Start()
go cron.Run()
max := int32(10)
for i := int32(0); i < max; i++ {
cron.AddFunc("* * * * * *", func() {