Skip to content

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

Merged
merged 12 commits into from
Dec 16, 2021
Merged

V2 #26

merged 12 commits into from
Dec 16, 2021

Conversation

ammario
Copy link
Member

@ammario ammario commented Dec 16, 2021

  • Remove Error type
    • When would a user want the wrapped error and not the underlying? The previous implementation introduced bug risk if consumers are checking error equality (e.g err == io.EOF)
  • Remove Listener
    • This is out of scope for a primitive retry library
  • Remove constant sleep
    • This can already be modeled by an exponential backoff when floor == ceil. Also: a constant sleep obviates much of the point of using a retry package in the first place.
  • Context is now required, following the Go idiom and letting us remove timeouts from the retry implementation
  • I removed a bunch of other functions too...

I didn't bother updating the major version since the import path was already updated following our new organization.

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.
@ammario ammario requested a review from kylecarbs December 16, 2021 14:40
README.md Outdated
@@ -1,18 +1,41 @@
# retry

An expressive, flexible retry package for Go.
A small retry package for Go.
Copy link
Member

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
Copy link
Member

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)
Copy link
Member

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.
Copy link
Member

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.
Copy link
Member

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.
@ammario ammario merged commit 9a5e97d into master Dec 16, 2021
@ammario ammario deleted the v2 branch December 16, 2021 15:54
func pingGoogle(ctx context.Context) error {
var err error
r := retry.New(time.Second, time.Second*10)
for r.Wait(ctx) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very clever @ammario!

Copy link
Contributor

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
Copy link
Contributor

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
Copy link
Contributor

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):
Copy link
Contributor

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
Copy link
Contributor

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
Copy link
Contributor

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.

Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants