mirror of
https://github.com/lxc/incus
synced 2026-08-02 05:26:46 +00:00
shared/subprocess/proc: Adds context support to Wait
Signed-off-by: Thomas Parrott <thomas.parrott@canonical.com>
This commit is contained in:
parent
2e6d28ceed
commit
2de4326052
@ -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()
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user