Skip to content

Commit

Permalink
add some new codes
Browse files Browse the repository at this point in the history
  • Loading branch information
Spillage committed May 16, 2024
1 parent fed5b54 commit 6f120fd
Showing 1 changed file with 32 additions and 1 deletion.
33 changes: 32 additions & 1 deletion solution1.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,35 @@
fmt.Printf("%s\n", p.Wait())
}
```
```
```
func main() {
ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second)
defer cancel()
timer := time.NewTimer(time.Duration(5 * time.Second))
var wg sync.WaitGroup
arr := [3]string{"a", "b", "c"}
for _, v := range arr {
wg.Add(1)
go func(ctx context.Context) {
defer wg.Done()
select {
case <-ctx.Done():
fmt.Println(fmt.Sprintf("call %s done", v))
timer.Stop()
timer.Reset(5 * time.Second)
return
case <-timer.C:
time.Sleep(50 * time.Second)
fmt.Println(v)
fmt.Println("timeout")
}
}(ctx)
}
wg.Wait()
}
```

0 comments on commit 6f120fd

Please sign in to comment.