builder/digitalocean: properly cleanup goroutines for status checking
This commit is contained in:
parent
4af230a4dc
commit
aedd1555d3
|
@ -9,6 +9,9 @@ import (
|
||||||
// waitForState simply blocks until the droplet is in
|
// waitForState simply blocks until the droplet is in
|
||||||
// a state we expect, while eventually timing out.
|
// a state we expect, while eventually timing out.
|
||||||
func waitForDropletState(desiredState string, dropletId uint, client *DigitalOceanClient, timeout time.Duration) error {
|
func waitForDropletState(desiredState string, dropletId uint, client *DigitalOceanClient, timeout time.Duration) error {
|
||||||
|
done := make(chan struct{})
|
||||||
|
defer close(done)
|
||||||
|
|
||||||
result := make(chan error, 1)
|
result := make(chan error, 1)
|
||||||
go func() {
|
go func() {
|
||||||
attempts := 0
|
attempts := 0
|
||||||
|
@ -29,6 +32,15 @@ func waitForDropletState(desiredState string, dropletId uint, client *DigitalOce
|
||||||
|
|
||||||
// Wait 3 seconds in between
|
// Wait 3 seconds in between
|
||||||
time.Sleep(3 * time.Second)
|
time.Sleep(3 * time.Second)
|
||||||
|
|
||||||
|
// Verify we shouldn't exit
|
||||||
|
select {
|
||||||
|
case <-done:
|
||||||
|
// We finished, so just exit the goroutine
|
||||||
|
return
|
||||||
|
default:
|
||||||
|
// Keep going
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue