2023-10-16 15:53:31 +00:00
|
|
|
// Copyright (c) HashiCorp, Inc.
|
|
|
|
// SPDX-License-Identifier: MPL-2.0
|
|
|
|
|
2023-06-16 20:29:50 +00:00
|
|
|
package retry
|
|
|
|
|
|
|
|
import "time"
|
|
|
|
|
|
|
|
// Timer repeats an operation for a given amount
|
|
|
|
// of time and waits between subsequent operations.
|
|
|
|
type Timer struct {
|
|
|
|
Timeout time.Duration
|
|
|
|
Wait time.Duration
|
|
|
|
|
|
|
|
// stop is the timeout deadline.
|
|
|
|
// TODO: Next()?
|
|
|
|
// Set on the first invocation of Next().
|
|
|
|
stop time.Time
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *Timer) Continue() bool {
|
|
|
|
if r.stop.IsZero() {
|
|
|
|
r.stop = time.Now().Add(r.Timeout)
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
if time.Now().After(r.stop) {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
time.Sleep(r.Wait)
|
|
|
|
return true
|
|
|
|
}
|