From 9b897faa0b99a45349b513ffc8dfe5c3cd2b7582 Mon Sep 17 00:00:00 2001 From: appleboy Date: Sat, 21 Dec 2024 10:06:53 +0800 Subject: [PATCH] perf: optimize output channel handling and improve test reliability - 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 --- example56-context-timeout/main.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/example56-context-timeout/main.go b/example56-context-timeout/main.go index 210e2c0..f5601e0 100644 --- a/example56-context-timeout/main.go +++ b/example56-context-timeout/main.go @@ -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++ { @@ -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):