From cec77391e82b54118a88db42438d7b43af6c54f5 Mon Sep 17 00:00:00 2001 From: Ben Hoyt Date: Mon, 9 Oct 2023 09:55:29 +1300 Subject: [PATCH] Use close and a non-buffered channel in contextAfterFunc; fix typo --- internals/overlord/state/notices.go | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/internals/overlord/state/notices.go b/internals/overlord/state/notices.go index 066b00d11..c592195ed 100644 --- a/internals/overlord/state/notices.go +++ b/internals/overlord/state/notices.go @@ -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() @@ -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(): @@ -414,10 +414,7 @@ func contextAfterFunc(ctx context.Context, f func()) func() { } }() stop := func() { - select { - case stopCh <- struct{}{}: - default: - } + close(stopCh) } return stop }