Skip to content

Commit

Permalink
fix: use time.After for deadline processing
Browse files Browse the repository at this point in the history
  • Loading branch information
juev committed Dec 29, 2023
1 parent 961eab5 commit aa190ac
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@
go.work

# tmp files
out
out
tor-relay-scanner-go
7 changes: 2 additions & 5 deletions scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand Down

0 comments on commit aa190ac

Please sign in to comment.