810
811
if !nextWakeup.IsZero() {
813
>
// A previous version of this workflow passed around sleep duration instead of wakeup time,
814
>
// which means it always set a timer even in cases where sleepTime comes out negative. For
815
>
// compatibility, we have to continue setting a positive timer in those cases. The value
816
>
// doesn't have to match, though.
817
>
if !s.tweakables.AllowZeroSleep && sleepTime <= 0 {
818
sleepTime = time.Second
819
}
820
// A previous version of this workflow always created a new timer here, which is wasteful.
821
// We can reuse a previous timer if we have the same deadline and it didn't fire yet.
823
>
if s.currentTimer == nil || !s.currentTimerDeadline.Equal(nextWakeup) {
824
>
s.currentTimer = workflow.NewTimer(s.ctx, sleepTime)
825
>
s.currentTimerDeadline = nextWakeup
826
>
}
827
>
sel.AddFuture(s.currentTimer, func(_ workflow.Future) {
828
s.currentTimer = nil
829
})