take context creation outside for loop

This commit is contained in:
Petar Marinov 2024-05-13 10:46:47 +03:00 committed by GitHub
parent 9990a8c753
commit 7f4fafb019
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -18,8 +18,8 @@ func consumer1(ch <-chan Event) {
}
func consumer2(ch <-chan Event) {
ctx, cancel := context.WithTimeout(context.Background(), time.Hour)
for {
ctx, cancel := context.WithTimeout(context.Background(), time.Hour)
select {
case event := <-ch:
cancel()