shared/subprocess/proc: Adds context support to Wait

Signed-off-by: Thomas Parrott <thomas.parrott@canonical.com>
This commit is contained in:
Thomas Parrott 2021-05-19 17:00:04 +01:00
parent 2e6d28ceed
commit 2de4326052

View File

@ -4,6 +4,7 @@
package subprocess
import (
"context"
"fmt"
"io/ioutil"
"os"
@ -254,11 +255,15 @@ func (p *Process) Signal(signal int64) error {
}
// Wait will wait for the given process object exit code
func (p *Process) Wait() (int64, error) {
func (p *Process) Wait(ctx context.Context) (int64, error) {
if !p.hasMonitor {
return -1, fmt.Errorf("Unable to wait on process we didn't spawn")
}
<-p.chExit
return p.exitCode, p.exitErr
select {
case <-p.chExit:
return p.exitCode, p.exitErr
case <-ctx.Done():
return -1, ctx.Err()
}
}