diff --git a/func.go b/func.go index 81eefb5..9941ee3 100644 --- a/func.go +++ b/func.go @@ -12,11 +12,8 @@ import ( // DoValue doesn't retry and returns the error. func DoValue[T any](ctx context.Context, policy *Policy, f func() (T, error)) (T, error) { var zero T - type Temporary interface { - Temporary() bool - } var err error - var target *Temporary + var target *temporary retrier := policy.Start(ctx) for retrier.Continue() { @@ -33,7 +30,7 @@ func DoValue[T any](ctx context.Context, policy *Policy, f func() (T, error)) (T if target == nil { // lazy allocation of target - target = new(Temporary) + target = new(temporary) } if errors.As(err, target) { if !(*target).Temporary() { diff --git a/retry.go b/retry.go index a40e0df..cea71da 100644 --- a/retry.go +++ b/retry.go @@ -60,11 +60,8 @@ func (p *Policy) Start(ctx context.Context) *Retrier { // If the error implements interface{ Temporary() bool } and Temporary() returns false, // Do doesn't retry and returns the error. func (p *Policy) Do(ctx context.Context, f func() error) error { - type Temporary interface { - Temporary() bool - } var err error - var target *Temporary + var target *temporary retrier := p.Start(ctx) for retrier.Continue() { @@ -80,7 +77,7 @@ func (p *Policy) Do(ctx context.Context, f func() error) error { if target == nil { // lazy allocation of target - target = new(Temporary) + target = new(temporary) } if errors.As(err, target) { if !(*target).Temporary() { @@ -94,6 +91,12 @@ func (p *Policy) Do(ctx context.Context, f func() error) error { return err } +type temporary interface { + Temporary() bool +} + +var _ temporary = (*permanentError)(nil) + type permanentError struct { error }