Skip to content

Commit

Permalink
fix: type declarations inside generic functions are not currently sup…
Browse files Browse the repository at this point in the history
…ported
  • Loading branch information
shogo82148 committed Dec 29, 2023
1 parent f6513a9 commit 875aa5d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
7 changes: 2 additions & 5 deletions func.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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() {
Expand Down
13 changes: 8 additions & 5 deletions retry.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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() {
Expand All @@ -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
}
Expand Down

0 comments on commit 875aa5d

Please sign in to comment.