diff options
| author | Shulhan <ms@kilabit.info> | 2023-05-02 01:13:36 +0700 |
|---|---|---|
| committer | Shulhan <ms@kilabit.info> | 2023-05-02 01:36:12 +0700 |
| commit | ec264a361f13d4c351dc7c2a0d93824526ee5c03 (patch) | |
| tree | bf521eae2e0331a0346d80f51ec2bcde86305dde | |
| parent | 8edbfaed99fdc197addbc2a4356f46e23e912813 (diff) | |
| download | pakakeh.go-ec264a361f13d4c351dc7c2a0d93824526ee5c03.tar.xz | |
lib/time: calculate the next event on Scheduler run
This allow user to call the Next method, to know the next time the
scheduler will be triggered, after receiving the event.
| -rw-r--r-- | lib/time/scheduler.go | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/lib/time/scheduler.go b/lib/time/scheduler.go index c23e0cb2..cb5d6d8d 100644 --- a/lib/time/scheduler.go +++ b/lib/time/scheduler.go @@ -568,15 +568,19 @@ func (sch *Scheduler) run() { for { select { case <-ticker.C: - // Notify the user and calculate the next event. - select { - case sch.c <- sch.next: - default: - } + // Calculate the next event and notify user. + // This will allow user to call the Next method after + // receiving the event. + var now = sch.next sch.calcNext(Now().UTC()) ticker.Reset(sch.nextDuration) + select { + case sch.c <- now: + default: + } + case <-sch.cstop: ticker.Stop() // Send ACK back to the stopper. |
