parent
0adf15dc3f
commit
53ae699acd
6
main.go
6
main.go
@ -89,12 +89,16 @@ func (sr *ShellRunner) Start() {
|
||||
// AddCommand adds a shell command to be executed with an optional callback.
|
||||
// No commands can be added if the runner has been stopped or not yet started.
|
||||
// The callback is executed asynchronously after the command has completed.
|
||||
// The order of command execution and callback invocation can be expected to be preserved.
|
||||
// The order of command execution and callback invocation can be expected to be preserved (maybe?).
|
||||
func (sr *ShellRunner) AddCommand(command string, callback func(*CommandResult)) error {
|
||||
cmd, cancel := sr.newShellCommand(command)
|
||||
return sr.AddCmd(cmd, callback, cancel)
|
||||
}
|
||||
|
||||
// AddCmd adds a pre-configured exec.Cmd to be executed with an optional callback and cancel function.
|
||||
// No commands can be added if the runner has been stopped or not yet started.
|
||||
// The callback is executed asynchronously after the command has completed.
|
||||
// The order of command execution and callback invocation can be expected to be preserved (maybe?).
|
||||
func (sr *ShellRunner) AddCmd(cmd *exec.Cmd, callback func(*CommandResult), cancel context.CancelFunc) error {
|
||||
sr.mu.Lock()
|
||||
defer sr.mu.Unlock()
|
||||
|
@ -78,9 +78,6 @@ func TestShellRunnerCallback(t *testing.T) {
|
||||
t.Fatalf("unexpected error adding command: %v", err)
|
||||
}
|
||||
|
||||
// Wait a sec for the worker to pick up the task
|
||||
time.Sleep(TaskStartWait)
|
||||
|
||||
callbackWait.Add(1)
|
||||
|
||||
if err := runner.AddCommand("echo callback b", func(result *tortoise.CommandResult) {
|
||||
@ -93,6 +90,9 @@ func TestShellRunnerCallback(t *testing.T) {
|
||||
t.Fatalf("unexpected error adding command: %v", err)
|
||||
}
|
||||
|
||||
// Wait a sec for the worker to pick up the task
|
||||
time.Sleep(TaskStartWait)
|
||||
|
||||
// Timeout waiting for callbacks
|
||||
done := make(chan struct{})
|
||||
go func() {
|
||||
|
Loading…
Reference in New Issue
Block a user