Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions cmd/catp/catp/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ import (
"io"
"log"
"os"
"os/signal"
"path/filepath"
"runtime/pprof"
"sort"
"strings"
"sync/atomic"
"syscall"
"time"

"github.com/bool64/dev/version"
Expand Down Expand Up @@ -238,6 +240,16 @@ func Main(options ...func(o *Options)) error { //nolint:funlen,cyclop,gocognit,g
r.sizes[fn] = st.Size()
}

shutdown := make(chan os.Signal, 1)
signal.Notify(shutdown, syscall.SIGINT, syscall.SIGTERM)

go func() {
<-shutdown

println("received signal, shutting down...")
atomic.StoreInt64(&r.closed, 1)
}()

if r.parallel >= 2 {
pr := r.pr
pr.Start(func(t *progress.Task) {
Expand Down
6 changes: 6 additions & 0 deletions cmd/catp/catp/catp.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
mu sync.Mutex
output io.Writer

closed int64

pr *progress.Progress
progressJSON string

Expand Down Expand Up @@ -220,6 +222,10 @@
for s.Scan() {
lines++

if atomic.LoadInt64(&r.closed) > 0 {
break

Check notice on line 226 in cmd/catp/catp/catp.go

View workflow job for this annotation

GitHub Actions / test (stable)

1 statement(s) on lines 225:226 are not covered by tests.
}

if r.limiter != nil {
_ = r.limiter.Wait(context.Background()) //nolint:errcheck // No failure condition here.
}
Expand Down
Loading