diff --git a/cli/htmgo/tasks/process/process.go b/cli/htmgo/tasks/process/process.go index ab0bf51..ddd332b 100644 --- a/cli/htmgo/tasks/process/process.go +++ b/cli/htmgo/tasks/process/process.go @@ -54,10 +54,11 @@ func shouldSkipKilling(flags []RunFlag, skipFlag []RunFlag) bool { func KillAll(skipFlag ...RunFlag) { tries := 0 + removeIndexes := make([]int, 0) for { tries++ allFinished := true - for _, cmd := range commands { + for i, cmd := range commands { if cmd.cmd.Process == nil { allFinished = false @@ -65,6 +66,7 @@ func KillAll(skipFlag ...RunFlag) { args := strings.Join(cmd.cmd.Args, " ") slog.Debug("process is not running after 50 tries, breaking.", slog.String("command", args)) allFinished = true + removeIndexes = append(removeIndexes, i) break } else { time.Sleep(time.Millisecond * 50) @@ -77,6 +79,10 @@ func KillAll(skipFlag ...RunFlag) { } } + for i := len(removeIndexes) - 1; i >= 0; i-- { + commands = append(commands[:removeIndexes[i]], commands[removeIndexes[i]+1:]...) + } + for _, command := range commands { if shouldSkipKilling(command.flags, skipFlag) { continue