Skip to content

Commit

Permalink
Use close and a non-buffered channel in contextAfterFunc; fix typo
Browse files Browse the repository at this point in the history
  • Loading branch information
benhoyt committed Oct 8, 2023
1 parent b715b16 commit cec7739
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions internals/overlord/state/notices.go
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ func (s *State) Notices(filter *NoticeFilter) []*Notice {
return notices
}

// Notice return a single notice by ID, or nil if not found.
// Notice returns a single notice by ID, or nil if not found.
func (s *State) Notice(id string) *Notice {
s.reading()

Expand Down Expand Up @@ -405,7 +405,7 @@ func (s *State) WaitNotices(ctx context.Context, filter *NoticeFilter) ([]*Notic

// Remove this and just use context.AfterFunc once we're on Go 1.21.
func contextAfterFunc(ctx context.Context, f func()) func() {
stopCh := make(chan struct{}, 1)
stopCh := make(chan struct{})
go func() {
select {
case <-ctx.Done():
Expand All @@ -414,10 +414,7 @@ func contextAfterFunc(ctx context.Context, f func()) func() {
}
}()
stop := func() {
select {
case stopCh <- struct{}{}:
default:
}
close(stopCh)
}
return stop
}

0 comments on commit cec7739

Please sign in to comment.