From be90aae85307714c986d1125947c1e6422ce6508 Mon Sep 17 00:00:00 2001 From: Benjamin Cane Date: Fri, 27 May 2022 11:28:22 -0700 Subject: [PATCH 1/2] adding delay only for late starters --- tasks.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tasks.go b/tasks.go index 8b22f7b..f3791a4 100644 --- a/tasks.go +++ b/tasks.go @@ -238,7 +238,11 @@ func (schd *Scheduler) AddWithID(id string, t *Task) error { t.id = id schd.tasks[t.id] = t - go schd.scheduleTask(t) + if time.Until(t.StartAfter) > time.Duration(0) { + go schd.scheduleTask(t) + return nil + } + schd.scheduleTask(t) return nil } From 52f3714c70fb981b19165117e41246ecceab88d7 Mon Sep 17 00:00:00 2001 From: Benjamin Cane Date: Fri, 27 May 2022 12:06:45 -0700 Subject: [PATCH 2/2] More efficient --- tasks.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tasks.go b/tasks.go index f3791a4..667ad49 100644 --- a/tasks.go +++ b/tasks.go @@ -238,11 +238,11 @@ func (schd *Scheduler) AddWithID(id string, t *Task) error { t.id = id schd.tasks[t.id] = t - if time.Until(t.StartAfter) > time.Duration(0) { - go schd.scheduleTask(t) + if t.StartAfter.IsZero() { + schd.scheduleTask(t) return nil } - schd.scheduleTask(t) + go schd.scheduleTask(t) return nil }