mirror of
https://github.com/status-im/consul.git
synced 2025-01-11 14:24:39 +00:00
efe279f802
* Add a make target to run lint-consul-retry on all the modules * Cleanup sdk/testutil/retry * Fix a bunch of retry.Run* usage to not use the outer testing.T * Fix some more recent retry lint issues and pin to v1.4.0 of lint-consul-retry * Fix codegen copywrite lint issues * Don’t perform cleanup after each retry attempt by default. * Use the common testutil.TestingTB interface in test-integ/tenancy * Fix retry tests * Update otel access logging extension test to perform requests within the retry block
31 lines
576 B
Go
31 lines
576 B
Go
// Copyright (c) HashiCorp, Inc.
|
|
// SPDX-License-Identifier: MPL-2.0
|
|
|
|
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
|
|
}
|