Skip to content

Commit

Permalink
Merge pull request #11 from avast/remove_units_func
Browse files Browse the repository at this point in the history
remove Units function
  • Loading branch information
JaSei authored Dec 3, 2018
2 parents a7162e2 + 676207c commit 7e26136
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 27 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ build:
go build

release: ## Release new version
git tag | grep -q $(VERSION) && echo This version was released! Increase VERSION! || git tag $(VERSION) && git push origin $(VERSION)
git tag | grep -q $(VERSION) && echo This version was released! Increase VERSION! || git tag $(VERSION) && git push origin $(VERSION) && git tag v$(VERSION) && git push origin v$(VERSION)

# Absolutely awesome: http://marmelab.com/blog/2016/02/29/auto-documented-makefile.html
help:
Expand Down
19 changes: 10 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,15 @@ nonintuitive interface (for me)

### BREAKING CHANGES

1.0.2 -> 2.0.0

* argument of `retry.Delay` is final delay (no multiplication by `retry.Units`
anymore)

* function `retry.Units` are removed

* [more about this breaking change](https://github.com/avast/retry-go/issues/7)

0.3.0 -> 1.0.0

* `retry.Retry` function are changed to `retry.Do` function
Expand Down Expand Up @@ -133,7 +142,7 @@ Attempts set count of retry default is 10
```go
func Delay(delay time.Duration) Option
```
Delay set delay between retry default are 1e5 units
Delay set delay between retry default is 100ms

#### func OnRetry

Expand Down Expand Up @@ -175,14 +184,6 @@ skip retry if special error example:
})
)

#### func Units

```go
func Units(units time.Duration) Option
```
Units set unit of delay (probably only for tests purpose) default are
microsecond

#### type RetryIfFunc

```go
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.0.2
2.0.0
13 changes: 2 additions & 11 deletions options.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ type OnRetryFunc func(n uint, err error)
type config struct {
attempts uint
delay time.Duration
units time.Duration
onRetry OnRetryFunc
retryIf RetryIfFunc
}
Expand All @@ -31,21 +30,13 @@ func Attempts(attempts uint) Option {
}

// Delay set delay between retry
// default are 1e5 units
// default is 100ms
func Delay(delay time.Duration) Option {
return func(c *config) {
c.delay = delay
}
}

// Units set unit of delay (probably only for tests purpose)
// default are microsecond
func Units(units time.Duration) Option {
return func(c *config) {
c.units = units
}
}

// OnRetry function callback are called each retry
//
// log each retry example:
Expand All @@ -54,7 +45,7 @@ func Units(units time.Duration) Option {
// func() error {
// return errors.New("some error")
// },
// retry.OnRetry(func(n unit, err error) {
// retry.OnRetry(func(n uint, err error) {
// log.Printf("#%d: %s\n", n, err)
// }),
// )
Expand Down
14 changes: 11 additions & 3 deletions retry.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,15 @@ SEE ALSO
BREAKING CHANGES
1.0.2 -> 2.0.0
* argument of `retry.Delay` is final delay (no multiplication by `retry.Units` anymore)
* function `retry.Units` are removed
* [more about this breaking change](https://github.com/avast/retry-go/issues/7)
0.3.0 -> 1.0.0
* `retry.Retry` function are changed to `retry.Do` function
Expand All @@ -70,8 +79,7 @@ func Do(retryableFunc RetryableFunc, opts ...Option) error {
//default
config := &config{
attempts: 10,
delay: 1e5,
units: time.Microsecond,
delay: 100 * time.Millisecond,
onRetry: func(n uint, err error) {},
retryIf: func(err error) bool { return true },
}
Expand Down Expand Up @@ -100,7 +108,7 @@ func Do(retryableFunc RetryableFunc, opts ...Option) error {
}

delayTime := config.delay * (1 << (n - 1))
time.Sleep((time.Duration)(delayTime) * config.units)
time.Sleep(delayTime)
} else {
return nil
}
Expand Down
4 changes: 2 additions & 2 deletions retry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ func TestDoAllFailed(t *testing.T) {
err := Do(
func() error { return errors.New("test") },
OnRetry(func(n uint, err error) { retrySum += n }),
Units(time.Nanosecond),
Delay(time.Nanosecond),
)
assert.Error(t, err)

Expand Down Expand Up @@ -57,7 +57,7 @@ func TestRetryIf(t *testing.T) {
RetryIf(func(err error) bool {
return err.Error() != "special"
}),
Units(time.Nanosecond),
Delay(time.Nanosecond),
)
assert.Error(t, err)

Expand Down

0 comments on commit 7e26136

Please sign in to comment.