43 lines
809 B
Go
43 lines
809 B
Go
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
// Copyright © 2023 Thorsten Schubert <tschubert@bafh.org>
|
|
|
|
package retry
|
|
|
|
import "time"
|
|
|
|
type NoneBackoff struct {
|
|
initialDelay time.Duration
|
|
maxRetries uint
|
|
currentRetries uint
|
|
}
|
|
|
|
func NewNoneBackoff(initialDelay time.Duration, maxRetries uint) *NoneBackoff {
|
|
return &NoneBackoff{
|
|
initialDelay: initialDelay,
|
|
maxRetries: maxRetries,
|
|
}
|
|
}
|
|
|
|
func (s *NoneBackoff) NextDelay() time.Duration {
|
|
return s.initialDelay
|
|
}
|
|
|
|
func (s *NoneBackoff) Next() bool {
|
|
if s.currentRetries >= s.maxRetries {
|
|
return false
|
|
}
|
|
s.currentRetries++
|
|
return true
|
|
}
|
|
|
|
func (s *NoneBackoff) Retries() (uint, uint) {
|
|
return s.currentRetries, s.maxRetries
|
|
}
|
|
|
|
func (s *NoneBackoff) Name() string {
|
|
return "none"
|
|
}
|
|
|
|
func (s *NoneBackoff) Reset() {
|
|
s.currentRetries = 0
|
|
}
|