blob: 1715458674bf32503a95749bd5a1c14eddb7c957 [file] [log] [blame]
Jon Perrittfa2c65e2014-10-02 20:32:43 -05001package gophercloud
2
3import (
4 "fmt"
Ash Wilsona8440642014-10-07 09:55:58 -04005 "strings"
Jon Perrittfa2c65e2014-10-02 20:32:43 -05006 "time"
7)
8
9// WaitFor polls a predicate function once per second up to secs times to wait for a certain state to arrive.
10func WaitFor(secs int, predicate func() (bool, error)) error {
11 for i := 0; i < secs; i++ {
12 time.Sleep(1 * time.Second)
13
14 satisfied, err := predicate()
15 if err != nil {
16 return err
17 }
18 if satisfied {
19 return nil
20 }
21 }
22 return fmt.Errorf("Time out in WaitFor.")
23}
Ash Wilsona8440642014-10-07 09:55:58 -040024
25// NormalizeURL ensures that each endpoint URL has a closing `/`, as expected by ServiceClient.
26func NormalizeURL(url string) string {
27 if !strings.HasSuffix(url, "/") {
28 return url + "/"
29 }
30 return url
31}