Skip to content

Commit

Permalink
Remove unnecessary channels
Browse files Browse the repository at this point in the history
  • Loading branch information
c032 committed Feb 15, 2024
1 parent 760cd91 commit 16301ae
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 20 deletions.
24 changes: 11 additions & 13 deletions tamrieltime/tamrieltime.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}
}
10 changes: 3 additions & 7 deletions time/notifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down

0 comments on commit 16301ae

Please sign in to comment.