From aa190aca4f4a67259dc7b38cee5135796b81061e Mon Sep 17 00:00:00 2001 From: Evsyukov Denis Date: Fri, 29 Dec 2023 15:24:42 +0300 Subject: [PATCH] fix: use time.After for deadline processing --- .gitignore | 3 ++- scanner.go | 7 ++----- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/.gitignore b/.gitignore index e587c3d..73a167e 100644 --- a/.gitignore +++ b/.gitignore @@ -21,4 +21,5 @@ go.work # tmp files -out \ No newline at end of file +out +tor-relay-scanner-go \ No newline at end of file diff --git a/scanner.go b/scanner.go index 3de1862..b0a5297 100644 --- a/scanner.go +++ b/scanner.go @@ -140,18 +140,15 @@ func (t *torRelayScanner) getRelays() Relays { progressbar.OptionSetVisibility(!t.silent), ) - ctx, cancel := context.WithTimeout(context.Background(), t.deadline) - defer cancel() - var relays Relays for i := 0; i < t.goal; i++ { select { case el := <-chanRelays: relays = append(relays, el) _ = bar.Add(1) - case <-ctx.Done(): + case <-time.After(t.deadline): _ = bar.Add(t.goal) - color.Fprintf(os.Stderr, "\nThe program was running for more than the specified time: %.2fm\n", t.deadline.Minutes()) + color.Fprintf(os.Stderr, "\nThe program was running for more than the specified time: %.2fs\n", t.deadline.Seconds()) os.Exit(1) } }