2021-12-02 11:12:23 +00:00
|
|
|
package soju
|
|
|
|
|
|
|
|
import (
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
|
|
|
// backoffer implements a simple exponential backoff.
|
|
|
|
type backoffer struct {
|
2024-04-07 20:58:24 +00:00
|
|
|
min, max, jitter time.Duration
|
|
|
|
n int64
|
2021-12-02 11:12:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func newBackoffer(min, max, jitter time.Duration) *backoffer {
|
2024-04-07 20:58:24 +00:00
|
|
|
// Initialize the struct with provided values, but these won't actually affect the backoff now.
|
|
|
|
return &backoffer{min: min, max: max, jitter: jitter}
|
2021-12-02 11:12:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (b *backoffer) Reset() {
|
2024-04-07 20:58:24 +00:00
|
|
|
b.n = 0
|
2021-12-02 11:12:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (b *backoffer) Next() time.Duration {
|
2024-04-07 20:58:24 +00:00
|
|
|
// Always return 0 to indicate no waiting period between retries.
|
|
|
|
return 0
|
2021-12-02 11:12:23 +00:00
|
|
|
}
|
2024-04-07 20:58:24 +00:00
|
|
|
|