File tree 14 files changed +63
-33
lines changed
14 files changed +63
-33
lines changed Original file line number Diff line number Diff line change
1
+ // Package retry provides the most advanced interruptible mechanism
2
+ // to perform actions repetitively until successful.
3
+ //
4
+ // The retry based on https://github.com/Rican7/retry but fully reworked
5
+ // and focused on integration with the https://github.com/kamilsk/breaker
6
+ // and the built-in https://pkg.go.dev/context package.
7
+ package retry
Original file line number Diff line number Diff line change @@ -11,17 +11,7 @@ func (err Error) Error() string { return string(err) }
11
11
// Unwrap always returns nil means that an error doesn't have other root cause.
12
12
func (err Error ) Unwrap () error { return nil }
13
13
14
- // equal to go.octolab.org/errors.Unwrap
15
14
func unwrap (err error ) error {
16
- // compatible with github.com/pkg/errors
17
- type causer interface {
18
- Cause () error
19
- }
20
- // compatible with built-in errors since 1.13
21
- type wrapper interface {
22
- Unwrap () error
23
- }
24
-
25
15
for err != nil {
26
16
layer , is := err .(wrapper )
27
17
if is {
@@ -37,3 +27,13 @@ func unwrap(err error) error {
37
27
}
38
28
return err
39
29
}
30
+
31
+ // compatible with github.com/pkg/errors
32
+ type causer interface {
33
+ Cause () error
34
+ }
35
+
36
+ // compatible with built-in errors since 1.13
37
+ type wrapper interface {
38
+ Unwrap () error
39
+ }
Original file line number Diff line number Diff line change @@ -17,18 +17,18 @@ func TestError(t *testing.T) {
17
17
}
18
18
19
19
func TestUnwrap (t * testing.T ) {
20
- cause := errors .New ("root" )
21
- core := unwrap (causer {layer {cause }})
22
- if ! reflect .DeepEqual (core , cause ) {
20
+ root := errors .New ("root" )
21
+ core := unwrap (cause {layer {root }})
22
+ if ! reflect .DeepEqual (core , root ) {
23
23
t .Error ("unexpected behavior" )
24
24
}
25
25
}
26
26
27
27
// helpers
28
28
29
- type causer struct { error }
29
+ type cause struct { error }
30
30
31
- func (causer causer ) Cause () error { return causer .error }
31
+ func (cause cause ) Cause () error { return cause .error }
32
32
33
33
type layer struct { error }
34
34
Original file line number Diff line number Diff line change 1
- package retry_test
1
+ package examples_test
2
2
3
3
import (
4
4
"context"
Original file line number Diff line number Diff line change
1
+ // Package examples contains extended documentation
2
+ // for github.com/kamilsk/retry/v5 module.
3
+ //
4
+ // It contains examples of usage with additional
5
+ // dependencies that are not needed by the module.
6
+ package examples
Original file line number Diff line number Diff line change
1
+ module github.com/kamilsk/retry/examples
2
+
3
+ go 1.13
4
+
5
+ require github.com/kamilsk/retry/v5 v5.0.0-rc8
6
+
7
+ replace github.com/kamilsk/retry/v5 => ../
Original file line number Diff line number Diff line change
1
+ package examples_test
Original file line number Diff line number Diff line change 1
- // Package retry provides the most advanced interruptible mechanism
2
- // to perform actions repetitively until successful.
3
- // The retry based on https://github.com/Rican7/retry but fully reworked
4
- // and focused on integration with the https://github.com/kamilsk/breaker
5
- // and the built-in https://pkg.go.dev/context package.
6
1
package retry
7
2
8
3
import (
Original file line number Diff line number Diff line change
1
+ // Package exp contains experimental unstable
2
+ // features.
3
+ package sandbox
Original file line number Diff line number Diff line change 1
- package retry_test
1
+ // +build go1.13
2
+
3
+ package sandbox_test
2
4
3
5
import (
4
6
"context"
5
7
"database/sql"
8
+ "errors"
6
9
"fmt"
7
10
"math/rand"
8
11
"net"
9
12
"time"
10
13
14
+ "github.com/kamilsk/retry/sandbox"
15
+
11
16
"github.com/kamilsk/retry/v5"
12
17
"github.com/kamilsk/retry/v5/backoff"
13
- "github.com/kamilsk/retry/v5/exp"
14
18
"github.com/kamilsk/retry/v5/jitter"
15
19
"github.com/kamilsk/retry/v5/strategy"
16
20
)
@@ -31,8 +35,8 @@ func Example() {
31
35
),
32
36
33
37
// experimental
34
- exp .CheckError (
35
- exp .NetworkError (exp .Skip ),
38
+ sandbox .CheckError (
39
+ sandbox .NetworkError (sandbox .Skip ),
36
40
DatabaseError (),
37
41
),
38
42
}
@@ -60,10 +64,10 @@ func SendRequest(ctx context.Context) error {
60
64
}
61
65
62
66
func DatabaseError () func (error ) bool {
63
- blacklist := []error {sql .ErrNoRows , sql .ErrConnDone , sql .ErrTxDone }
67
+ deprecated := []error {sql .ErrNoRows , sql .ErrConnDone , sql .ErrTxDone }
64
68
return func (err error ) bool {
65
- for _ , preset := range blacklist {
66
- if err == preset {
69
+ for _ , deprecated := range deprecated {
70
+ if errors . Is ( err , deprecated ) {
67
71
return false
68
72
}
69
73
}
Original file line number Diff line number Diff line change
1
+ module github.com/kamilsk/retry/sandbox
2
+
3
+ go 1.11
4
+
5
+ require github.com/kamilsk/retry/v5 v5.0.0-rc8
6
+
7
+ replace github.com/kamilsk/retry/v5 => ../
Original file line number Diff line number Diff line change 1
- package exp
1
+ package sandbox
2
2
3
3
import "net"
4
4
9
9
10
10
// A Breaker carries a cancellation signal to interrupt an action execution.
11
11
//
12
- // It is a subset of the built-in Context and github.com/kamilsk/breaker interfaces.
12
+ // It is a subset of the built-in context and github.com/kamilsk/breaker interfaces.
13
13
type Breaker = interface {
14
14
// Done returns a channel that's closed when a cancellation signal occurred.
15
15
Done () <- chan struct {}
Original file line number Diff line number Diff line change 1
- package exp_test
1
+ package sandbox_test
2
2
3
3
import (
4
4
"context"
7
7
"net"
8
8
"testing"
9
9
10
- . "github.com/kamilsk/retry/v5/exp "
10
+ . "github.com/kamilsk/retry/sandbox "
11
11
)
12
12
13
13
func TestCheckError (t * testing.T ) {
Original file line number Diff line number Diff line change @@ -5,7 +5,7 @@ import "time"
5
5
6
6
// A Breaker carries a cancellation signal to interrupt an action execution.
7
7
//
8
- // It is a subset of the built-in Context and github.com/kamilsk/breaker interfaces.
8
+ // It is a subset of the built-in context and github.com/kamilsk/breaker interfaces.
9
9
type Breaker = interface {
10
10
// Done returns a channel that's closed when a cancellation signal occurred.
11
11
Done () <- chan struct {}
You can’t perform that action at this time.
0 commit comments