update-repos/internal/retry/none.go
2023-12-06 14:24:08 +01:00

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
}