Thanks to visit codestin.com
Credit goes to github.com

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

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2018 Coder Technologies Inc.
Copyright (c) 2021 Coder Technologies Inc.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
51 changes: 41 additions & 10 deletions README.md
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.

[![GoDoc](https://godoc.org/github.com/golang/gddo?status.svg)](https://godoc.org/go.coder.com/retry)
[![GoDoc](https://godoc.org/github.com/golang/gddo?status.svg)](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
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 := 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

_, 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
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.

}
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

}
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.

}
```
54 changes: 0 additions & 54 deletions backoff.go

This file was deleted.

58 changes: 0 additions & 58 deletions backoff_test.go

This file was deleted.

2 changes: 1 addition & 1 deletion doc.go
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
9 changes: 2 additions & 7 deletions go.mod
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
8 changes: 0 additions & 8 deletions go.sum
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=
46 changes: 0 additions & 46 deletions listener.go

This file was deleted.

110 changes: 0 additions & 110 deletions listener_test.go

This file was deleted.

Loading