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"
|
|
|
|
|
|
|
|
// Counter repeats an operation a given number of
|
|
|
|
// times and waits between subsequent operations.
|
|
|
|
type Counter struct {
|
|
|
|
Count int
|
|
|
|
Wait time.Duration
|
|
|
|
|
|
|
|
count int
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *Counter) Continue() bool {
|
|
|
|
if r.count == r.Count {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
if r.count > 0 {
|
|
|
|
time.Sleep(r.Wait)
|
|
|
|
}
|
|
|
|
r.count++
|
|
|
|
return true
|
|
|
|
}
|