From cdd84724126e17c974f89eb5a72e6576299929ab Mon Sep 17 00:00:00 2001 From: Leah Neukirchen Date: Sat, 24 Feb 2024 00:43:44 +0100 Subject: cancel context after max count is reached --- htping.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/htping.go b/htping.go index b480237..cfeb236 100644 --- a/htping.go +++ b/htping.go @@ -333,7 +333,8 @@ func main() { network = "tcp6" } - ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt) + ctx, cancel := context.WithCancel(context.Background()) + ctx, stop := signal.NotifyContext(ctx, os.Interrupt) defer stop() var wg sync.WaitGroup @@ -434,7 +435,7 @@ func main() { count++ for { if *maxCount > 0 && count > *maxCount { - break + cancel() } select { case <-ctx.Done(): -- cgit 1.4.1