mirror of
https://github.com/teivah/100-go-mistakes.git
synced 2026-06-25 10:56:52 +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) {
|
func consumer2(ch <-chan Event) {
|
||||||
|
ctx, cancel := context.WithTimeout(context.Background(), time.Hour)
|
||||||
for {
|
for {
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), time.Hour)
|
|
||||||
select {
|
select {
|
||||||
case event := <-ch:
|
case event := <-ch:
|
||||||
cancel()
|
cancel()
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue