-
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
V2 #26
Changes from all commits
b470eb0
31e070a
b2f1f36
6c488e9
a2f4222
b59fe26
723e29f
94fab55
767eb4f
98056d8
e3b5d86
90c791f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,49 @@ | ||
# retry | ||
|
||
An expressive, flexible retry package for Go. | ||
An exponentially backing off retry package for Go. | ||
|
||
[](https://godoc.org/go.coder.com/retry) | ||
[](https://godoc.org/github.com/coder/retry) | ||
|
||
## Features | ||
``` | ||
go get github.com/coder/retry | ||
``` | ||
|
||
- Backoff helper | ||
- Retrying net.Listener wrapper | ||
## Features | ||
- Offers a `for` loop experience instead of closures | ||
- Only 2 exported methods | ||
- No external dependencies | ||
|
||
## Examples | ||
|
||
See [retry_example_test.go](retry_example_test.go) | ||
|
||
## We're Hiring! | ||
|
||
If you're a passionate Go developer, send your resume and/or GitHub link to [[email protected]](mailto:[email protected]). | ||
Wait for connectivity to google.com, checking at most once every | ||
second. | ||
```go | ||
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 commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. lmfao just realized this was the API from before |
||
_, err = http.Get("https://google.com") | ||
if err != nil { | ||
continue | ||
} | ||
break | ||
} | ||
return err | ||
} | ||
``` | ||
|
||
Wait for connectivity to google.com, checking at most 10 times. | ||
```go | ||
func pingGoogle(ctx context.Context) error { | ||
var err error | ||
r := retry.New(time.Second, time.Second*10) | ||
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 commentThe 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 commentThe 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. |
||
} | ||
break | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bad indentation |
||
} | ||
return err | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just return nil here. |
||
} | ||
``` |
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
// Package retry contains utilities for retrying an action until it succeeds. | ||
// Package retry runs a failable function until it succeeds. | ||
package retry |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,3 @@ | ||
module go.coder.com/retry | ||
module github.com/coder/retry | ||
|
||
require ( | ||
github.com/davecgh/go-spew v1.1.0 // indirect | ||
github.com/pkg/errors v0.8.0 | ||
github.com/pmezard/go-difflib v1.0.0 // indirect | ||
github.com/stretchr/testify v1.1.4 | ||
) | ||
go 1.17 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +0,0 @@ | ||
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= | ||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= | ||
github.com/pkg/errors v0.8.0 h1:WdK/asTD0HN+q6hsWO3/vpuAkAr+tw6aNJNDFFf0+qw= | ||
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= | ||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= | ||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= | ||
github.com/stretchr/testify v1.1.4 h1:ToftOQTytwshuOSj6bDSolVUa3GINfJP/fg3OkkOzQQ= | ||
github.com/stretchr/testify v1.1.4/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= | ||
This file was deleted.
This file was deleted.
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