Merge pull request #321 from numtide/softer-cancel

Softer cancel
This commit is contained in:
Brian McGee 2024-06-15 11:28:48 +01:00 committed by GitHub
commit 30d30b54f0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 8 additions and 2 deletions

View File

@ -325,9 +325,11 @@ func (f *Format) walkFilesystem(ctx context.Context) func() error {
}
}
// applyFormatters
func (f *Format) applyFormatters(ctx context.Context) func() error {
// create our own errgroup for concurrent formatting tasks
fg, ctx := errgroup.WithContext(ctx)
// create our own errgroup for concurrent formatting tasks.
// we don't want a cancel clause, in order to let formatters run up to the end.
fg := errgroup.Group{}
// simple optimization to avoid too many concurrent formatting tasks
// we can queue them up faster than the formatters can process them, this paces things a bit
fg.SetLimit(runtime.NumCPU())

View File

@ -64,6 +64,10 @@ func (f *Formatter) Apply(ctx context.Context, tasks []*Task) error {
// execute the command
cmd := exec.CommandContext(ctx, f.executable, args...)
// replace the default Cancel handler installed by CommandContext because it sends SIGKILL (-9).
cmd.Cancel = func() error {
return cmd.Process.Signal(os.Interrupt)
}
cmd.Dir = f.workingDir
// log out the command being executed