mirror of
https://github.com/teivah/100-go-mistakes.git
synced 2026-06-21 17:07:18 +08:00
take context creation outside for loop
This commit is contained in:
parent
9990a8c753
commit
7f4fafb019
1 changed files with 1 additions and 1 deletions
|
|
@ -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()
|
||||
|
|
|
|||
Loading…
Reference in a new issue