diff options
author | Leah Neukirchen <leah@vuxu.org> | 2024-02-24 00:43:44 +0100 |
---|---|---|
committer | Leah Neukirchen <leah@vuxu.org> | 2024-02-24 00:43:44 +0100 |
commit | cdd84724126e17c974f89eb5a72e6576299929ab (patch) | |
tree | 570a8564b37b2a9db824c091743c01499b5e046e | |
parent | 3a6c485329aa4e35c4b0a080154e78a775ee3a9a (diff) | |
download | htping-cdd84724126e17c974f89eb5a72e6576299929ab.tar.gz htping-cdd84724126e17c974f89eb5a72e6576299929ab.tar.xz htping-cdd84724126e17c974f89eb5a72e6576299929ab.zip |
cancel context after max count is reached
-rw-r--r-- | htping.go | 5 |
1 files 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(): |