Skip to content

Commit

Permalink
fix merge
Browse files Browse the repository at this point in the history
  • Loading branch information
wxiaoguang committed Mar 31, 2022
1 parent a75b8c8 commit 4daf8ca
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
5 changes: 5 additions & 0 deletions modules/process/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,11 @@ func (pm *Manager) AddTypedContext(parent context.Context, description, processT
// Most processes will not need to use the cancel function but there will be cases whereby you want to cancel the process but not immediately remove it from the
// process table.
func (pm *Manager) AddContextTimeout(parent context.Context, timeout time.Duration, description string) (ctx context.Context, cancel context.CancelFunc, finshed FinishedFunc) {
if timeout <= 0 {
// it's meaningless to use timeout <= 0, and it must be a bug! so we must panic here to tell developers to make the timeout correct
panic("the timeout must be greater than zero, otherwise the context will be cancelled immediately")
}

ctx, cancel = context.WithTimeout(parent, timeout)

ctx, _, finshed = pm.Add(ctx, description, cancel, NormalProcessType, true)
Expand Down
4 changes: 2 additions & 2 deletions modules/process/manager_exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ func (pm *Manager) ExecDirEnv(ctx context.Context, timeout time.Duration, dir, d
}

// ExecDirEnvStdIn runs a command in given path and environment variables with provided stdIN, and waits for its completion
// up to the given timeout (or DefaultTimeout if -1 is given).
// up to the given timeout (or DefaultTimeout if timeout <= 0 is given).
// Returns its complete stdout and stderr
// outputs and an error, if any (including timeout)
func (pm *Manager) ExecDirEnvStdIn(ctx context.Context, timeout time.Duration, dir, desc string, env []string, stdIn io.Reader, cmdName string, args ...string) (string, string, error) {
if timeout == -1 {
if timeout <= 0 {
timeout = 60 * time.Second
}

Expand Down

0 comments on commit 4daf8ca

Please sign in to comment.