Skip to content

Commit 9cb6780

Browse files
entropidelicMarcosNicolau
authored andcommitted
Add some docs
1 parent 8bfd336 commit 9cb6780

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

core/connection.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package connection
22

33
import (
4-
"fmt"
54
"time"
65

76
"github.com/cenkalti/backoff/v4"
@@ -20,11 +19,15 @@ func (e PermanentError) Is(err error) bool {
2019
return ok
2120
}
2221

22+
// Retries a given function in an exponential backoff manner.
23+
// It will retry calling the function while it returns an error, until the max retries
24+
// from the configuration are reached, or until a `PermanentError` is returned.
25+
// The function to be retried should return `PermanentError` when the condition for stop retrying
26+
// is met.
2327
func Retry(functionToRetry func() (interface{}, error), minDelay uint64, factor float64, maxTries uint64) (interface{}, error) {
2428
f := func() (interface{}, error) {
2529
val, err := functionToRetry()
2630
if perm, ok := err.(PermanentError); err != nil && ok {
27-
fmt.Println("ENTRE")
2831
return nil, backoff.Permanent(perm.Inner)
2932
}
3033
return val, err

core/connection_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ func DummyFunction(x uint64) (uint64, error) {
1818
}
1919

2020
func TestRetry(t *testing.T) {
21-
function := func() (interface{}, error) { return DummyFunction(42) }
21+
function := func() (interface{}, error) { return DummyFunction(43) }
2222
data, err := connection.Retry(function, 1000, 2, 3)
2323
if err != nil {
2424
t.Errorf("Retry error!: %s", err)

0 commit comments

Comments
 (0)