-
Notifications
You must be signed in to change notification settings - Fork 2
V2 #26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Remove the Listener implementation in the interest of doing one thing and doing it well. We can add it back in another package down the line.
README.md
Outdated
@@ -1,18 +1,41 @@ | |||
# retry | |||
|
|||
An expressive, flexible retry package for Go. | |||
A small retry package for Go. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't really tell me what retry means in this context.
Neither did the old statement, but 🤷♀️
README.md
Outdated
- Backoff helper | ||
- Retrying net.Listener wrapper | ||
## Features | ||
- For loop experience instead of closures |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"For" should probably be in backticks to indicate the keyword
README.md
Outdated
r := retry.New(time.Second, time.Second*10) | ||
for r.Wait(ctx) { | ||
_, err := http.Get("https://google.com") | ||
r.SetError(err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need a set error function? Couldn't we return if there's an error? If there's no error, the user would break.
What's the advantage over using a ticker? Is it the maximum retries?
retrier.go
Outdated
"time" | ||
) | ||
|
||
// Retrier represents a retry instance. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not indicative of what this does. There is no "retry" instance.
err *error | ||
} | ||
|
||
// New creates a retrier that exponentially backs off from floor to ceil pauses. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good comment!
We can always add it back later.
func pingGoogle(ctx context.Context) error { | ||
var err error | ||
r := retry.New(time.Second, time.Second*10) | ||
for r.Wait(ctx) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very clever @ammario!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lmfao just realized this was the API from before
second. | ||
```go | ||
func pingGoogle(ctx context.Context) error { | ||
var err error |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bad indentation
if err != nil { | ||
continue | ||
} | ||
break |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bad indentation
r.delay = r.ceil | ||
} | ||
select { | ||
case <-time.After(r.delay): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might be a good idea to use time.NewTimer here to avoid memory usage when things are failing consistently and contexts are being cancelled.
} | ||
break | ||
} | ||
return err |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just return nil here.
for n := 0; r.Wait(ctx) && n < 10; n++ { | ||
_, err = http.Get("https://google.com") | ||
if err != nil { | ||
continue |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Flip this and return nil.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then you don't need to declare err above either. Or need a break/return below.
Error
typeerr == io.EOF
)Listener
floor == ceil
. Also: a constant sleep obviates much of the point of using a retry package in the first place.I didn't bother updating the major version since the import path was already updated following our new organization.