Jon Perritt | fa2c65e | 2014-10-02 20:32:43 -0500 | [diff] [blame] | 1 | package snapshots |
| 2 | |
| 3 | import ( |
| 4 | "github.com/rackspace/gophercloud" |
| 5 | ) |
| 6 | |
Jamie Hannaford | d8275bb | 2014-10-06 16:12:23 +0200 | [diff] [blame] | 7 | // WaitForStatus will continually poll the resource, checking for a particular |
| 8 | // status. It will do this for the amount of seconds defined. |
Jon Perritt | fa2c65e | 2014-10-02 20:32:43 -0500 | [diff] [blame] | 9 | func WaitForStatus(c *gophercloud.ServiceClient, id, status string, secs int) error { |
| 10 | return gophercloud.WaitFor(secs, func() (bool, error) { |
| 11 | current, err := Get(c, id).Extract() |
| 12 | if err != nil { |
| 13 | return false, err |
| 14 | } |
| 15 | |
| 16 | if current.Status == status { |
| 17 | return true, nil |
| 18 | } |
| 19 | |
| 20 | return false, nil |
| 21 | }) |
| 22 | } |