diff --git a/tamrieltime/tamrieltime.go b/tamrieltime/tamrieltime.go index dfcd2aa..6fd410f 100644 --- a/tamrieltime/tamrieltime.go +++ b/tamrieltime/tamrieltime.go @@ -67,24 +67,22 @@ var _ dsts.StatusLineBlockProvider = TamrielTime // TamrielTime is a `dsts.StatusProviderFunc` for displaying the current date // and time in the format used by Skyrim. func TamrielTime(ctx context.Context, ch chan<- dsts.StatusLineBlock) error { - firstTick := make(chan struct{}) - go func() { - firstTick <- struct{}{} - }() + onTick := func() { + ch <- dsts.StatusLineBlock{ + FullText: Format(time.Now()), + Color: "#999999", + } + } + + // First tick. + onTick() + for { select { case <-ctx.Done(): return nil - case <-firstTick: - ch <- dsts.StatusLineBlock{ - FullText: Format(time.Now()), - Color: "#999999", - } case <-time.After(500 * time.Millisecond): - ch <- dsts.StatusLineBlock{ - FullText: Format(time.Now()), - Color: "#999999", - } + onTick() } } } diff --git a/time/notifier.go b/time/notifier.go index fcd3645..c782122 100644 --- a/time/notifier.go +++ b/time/notifier.go @@ -71,23 +71,19 @@ func (tn *Notifier) initWithLock() { tn.ticker = time.NewTicker(200 * time.Millisecond) go func(ctx context.Context, tick <-chan time.Time) { - firstTick := make(chan struct{}) - go func() { - firstTick <- struct{}{} - }() - onTick := func() { now := time.Now() tn.update(now) tn.runCallbacks() } + // First tick. + onTick() + for { select { case <-ctx.Done(): return - case <-firstTick: - onTick() case <-tick: onTick() }