Skip to content

Commit 7e26136

Browse files
authored
Merge pull request #11 from avast/remove_units_func
remove Units function
2 parents a7162e2 + 676207c commit 7e26136

File tree

6 files changed

+27
-27
lines changed

6 files changed

+27
-27
lines changed

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ build:
5757
go build
5858

5959
release: ## Release new version
60-
git tag | grep -q $(VERSION) && echo This version was released! Increase VERSION! || git tag $(VERSION) && git push origin $(VERSION)
60+
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)
6161

6262
# Absolutely awesome: http://marmelab.com/blog/2016/02/29/auto-documented-makefile.html
6363
help:

README.md

+10-9
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,15 @@ nonintuitive interface (for me)
6464

6565
### BREAKING CHANGES
6666

67+
1.0.2 -> 2.0.0
68+
69+
* argument of `retry.Delay` is final delay (no multiplication by `retry.Units`
70+
anymore)
71+
72+
* function `retry.Units` are removed
73+
74+
* [more about this breaking change](https://github.com/avast/retry-go/issues/7)
75+
6776
0.3.0 -> 1.0.0
6877

6978
* `retry.Retry` function are changed to `retry.Do` function
@@ -133,7 +142,7 @@ Attempts set count of retry default is 10
133142
```go
134143
func Delay(delay time.Duration) Option
135144
```
136-
Delay set delay between retry default are 1e5 units
145+
Delay set delay between retry default is 100ms
137146

138147
#### func OnRetry
139148

@@ -175,14 +184,6 @@ skip retry if special error example:
175184
})
176185
)
177186

178-
#### func Units
179-
180-
```go
181-
func Units(units time.Duration) Option
182-
```
183-
Units set unit of delay (probably only for tests purpose) default are
184-
microsecond
185-
186187
#### type RetryIfFunc
187188

188189
```go

VERSION

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.0.2
1+
2.0.0

options.go

+2-11
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ type OnRetryFunc func(n uint, err error)
1414
type config struct {
1515
attempts uint
1616
delay time.Duration
17-
units time.Duration
1817
onRetry OnRetryFunc
1918
retryIf RetryIfFunc
2019
}
@@ -31,21 +30,13 @@ func Attempts(attempts uint) Option {
3130
}
3231

3332
// Delay set delay between retry
34-
// default are 1e5 units
33+
// default is 100ms
3534
func Delay(delay time.Duration) Option {
3635
return func(c *config) {
3736
c.delay = delay
3837
}
3938
}
4039

41-
// Units set unit of delay (probably only for tests purpose)
42-
// default are microsecond
43-
func Units(units time.Duration) Option {
44-
return func(c *config) {
45-
c.units = units
46-
}
47-
}
48-
4940
// OnRetry function callback are called each retry
5041
//
5142
// log each retry example:
@@ -54,7 +45,7 @@ func Units(units time.Duration) Option {
5445
// func() error {
5546
// return errors.New("some error")
5647
// },
57-
// retry.OnRetry(func(n unit, err error) {
48+
// retry.OnRetry(func(n uint, err error) {
5849
// log.Printf("#%d: %s\n", n, err)
5950
// }),
6051
// )

retry.go

+11-3
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,15 @@ SEE ALSO
4545
4646
BREAKING CHANGES
4747
48+
1.0.2 -> 2.0.0
49+
50+
* argument of `retry.Delay` is final delay (no multiplication by `retry.Units` anymore)
51+
52+
* function `retry.Units` are removed
53+
54+
* [more about this breaking change](https://github.com/avast/retry-go/issues/7)
55+
56+
4857
0.3.0 -> 1.0.0
4958
5059
* `retry.Retry` function are changed to `retry.Do` function
@@ -70,8 +79,7 @@ func Do(retryableFunc RetryableFunc, opts ...Option) error {
7079
//default
7180
config := &config{
7281
attempts: 10,
73-
delay: 1e5,
74-
units: time.Microsecond,
82+
delay: 100 * time.Millisecond,
7583
onRetry: func(n uint, err error) {},
7684
retryIf: func(err error) bool { return true },
7785
}
@@ -100,7 +108,7 @@ func Do(retryableFunc RetryableFunc, opts ...Option) error {
100108
}
101109

102110
delayTime := config.delay * (1 << (n - 1))
103-
time.Sleep((time.Duration)(delayTime) * config.units)
111+
time.Sleep(delayTime)
104112
} else {
105113
return nil
106114
}

retry_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ func TestDoAllFailed(t *testing.T) {
1313
err := Do(
1414
func() error { return errors.New("test") },
1515
OnRetry(func(n uint, err error) { retrySum += n }),
16-
Units(time.Nanosecond),
16+
Delay(time.Nanosecond),
1717
)
1818
assert.Error(t, err)
1919

@@ -57,7 +57,7 @@ func TestRetryIf(t *testing.T) {
5757
RetryIf(func(err error) bool {
5858
return err.Error() != "special"
5959
}),
60-
Units(time.Nanosecond),
60+
Delay(time.Nanosecond),
6161
)
6262
assert.Error(t, err)
6363

0 commit comments

Comments
 (0)