Skip to content

Commit

Permalink
perf: optimize output channel handling and improve test reliability
Browse files Browse the repository at this point in the history
- Increase the buffer size of the `output` channel from `1` to `10`
- Add a sleep to simulate a slow consumer in the `output` channel processing

Signed-off-by: appleboy <[email protected]>
  • Loading branch information
appleboy committed Dec 21, 2024
1 parent 69daa8a commit 9b897fa
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion example56-context-timeout/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
)

func main() {
output := make(chan int, 1)
output := make(chan int, 10)

go func() {
for i := 0; i < 30; i++ {
Expand All @@ -18,6 +18,8 @@ func main() {
for {
select {
case val := <-output:
// simulate slow consumer
time.Sleep(500 * time.Millisecond)
println("output:", val)
// how to fix the timeout issue?
case <-time.After(1 * time.Second):
Expand Down

0 comments on commit 9b897fa

Please sign in to comment.