Skip to content

Commit 3eddb06

Browse files
committed
Add nice README
1 parent 1d07491 commit 3eddb06

File tree

4 files changed

+103
-1
lines changed

4 files changed

+103
-1
lines changed

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2018 Coder Technologies Inc.
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in
13+
all copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
THE SOFTWARE.

README.md

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# retry
2+
3+
An expressive, flexible retry package for Go.
4+
5+
[![GoDoc](https://godoc.org/github.com/golang/gddo?status.svg)](https://godoc.org/github.com/codercom/retry)
6+
7+
## Features
8+
9+
- Exponential backoff
10+
- Jitter
11+
- Bound to context
12+
- Bound to timeout
13+
- Bound to attempt count
14+
- Bound to certain kinds of errors
15+
- Any combination of the above
16+
- Retrying net.Listener wrapper
17+
18+
## Examples
19+
20+
This code will succeed after about a second.
21+
22+
```go
23+
start := time.Now()
24+
25+
err := retry.New(time.Millisecond).
26+
Backoff(time.Millisecond * 50).
27+
Timeout(time.Second * 2).
28+
Run(
29+
func() error {
30+
if time.Since(start) < time.Second {
31+
return errors.New("not enough time has elapsed")
32+
}
33+
return nil
34+
},
35+
)
36+
fmt.Printf("err: %v, took %v\n", err, time.Since(start))
37+
```
38+
39+
---
40+
41+
This code will block forever, since no `Timeout` or `Context` option
42+
was provided.
43+
44+
```go
45+
start := time.Now()
46+
47+
err := retry.New(time.Millisecond).
48+
Backoff(time.Millisecond * 50).
49+
Run(
50+
func() error {
51+
return errors.New("not enough time has elapsed")
52+
},
53+
)
54+
fmt.Printf("err: %v, took %v\n", err, time.Since(start))
55+
```

examples/backoff/main.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package main
2+
3+
import (
4+
"errors"
5+
"fmt"
6+
"time"
7+
8+
"github.com/codercom/retry"
9+
)
10+
11+
func main() {
12+
start := time.Now()
13+
14+
err := retry.New(time.Millisecond).
15+
Backoff(time.Millisecond * 50).
16+
Timeout(time.Second * 2).
17+
Run(
18+
func() error {
19+
if time.Since(start) < time.Second {
20+
return errors.New("not enough time has elapsed")
21+
}
22+
return nil
23+
},
24+
)
25+
fmt.Printf("err: %v, took %v\n", err, time.Since(start))
26+
}

listener_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ func TestListener(t *testing.T) {
9797
case 3:
9898
return nil, nil
9999
default:
100-
t.Fatal("test listener called too many times; callCount: %v", callCount)
100+
t.Fatalf("test listener called too many times; callCount: %v", callCount)
101101
panic("unreachable")
102102
}
103103
}

0 commit comments

Comments
 (0)