From 7f4fafb01915951bc9536181800da48ffd435c45 Mon Sep 17 00:00:00 2001 From: Petar Marinov Date: Mon, 13 May 2024 10:46:47 +0300 Subject: [PATCH] take context creation outside for loop --- src/10-standard-lib/76-time-after/main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/10-standard-lib/76-time-after/main.go b/src/10-standard-lib/76-time-after/main.go index 56f7004..de7aff4 100644 --- a/src/10-standard-lib/76-time-after/main.go +++ b/src/10-standard-lib/76-time-after/main.go @@ -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()