Remove `first` variable an extra if block

clean up the code slighly by moving the Sleep in WaitForState to the end
of the loop.
This commit is contained in:
James Bardin 2016-08-30 17:56:26 -04:00
parent 82be35a797
commit 481f12cf2c
1 changed files with 22 additions and 24 deletions

View File

@ -81,30 +81,7 @@ func (conf *StateChangeConf) WaitForState() (interface{}, error) {
wait := 100 * time.Millisecond
for first := true; ; first = false {
if !first {
// If a poll interval has been specified, choose that interval.
// Otherwise bound the default value.
if conf.PollInterval > 0 && conf.PollInterval < 180*time.Second {
wait = conf.PollInterval
} else {
if wait < conf.MinTimeout {
wait = conf.MinTimeout
} else if wait > 10*time.Second {
wait = 10 * time.Second
}
}
log.Printf("[TRACE] Waiting %s before next try", wait)
time.Sleep(wait)
// Wait between refreshes using exponential backoff, except when
// waiting for the target state to reoccur.
if targetOccurence == 0 {
wait *= 2
}
}
for {
res, currentState, err := conf.Refresh()
result := Result{
Result: res,
@ -173,6 +150,27 @@ func (conf *StateChangeConf) WaitForState() (interface{}, error) {
return
}
}
// If a poll interval has been specified, choose that interval.
// Otherwise bound the default value.
if conf.PollInterval > 0 && conf.PollInterval < 180*time.Second {
wait = conf.PollInterval
} else {
if wait < conf.MinTimeout {
wait = conf.MinTimeout
} else if wait > 10*time.Second {
wait = 10 * time.Second
}
}
log.Printf("[TRACE] Waiting %s before next try", wait)
time.Sleep(wait)
// Wait between refreshes using exponential backoff, except when
// waiting for the target state to reoccur.
if targetOccurence == 0 {
wait *= 2
}
}
}()