mirror of
https://github.com/duke-git/lancet.git
synced 2026-02-14 01:32:27 +08:00
fix 删除文档中废弃的RetryDuration函数 (#240)
* fix 修改文档中已经删除的函数RetryDuration,替换为RetryWithLinearBackoff * fix 删除主文档中的废弃函数 --------- Co-authored-by: dongyue16 <dongyue16@tal.com>
This commit is contained in:
@@ -1200,9 +1200,6 @@ import "github.com/duke-git/lancet/v2/retry"
|
|||||||
- **<big>RetryFunc</big>** : 重试执行的函数。
|
- **<big>RetryFunc</big>** : 重试执行的函数。
|
||||||
[[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/retry.md#RetryFunc)]
|
[[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/retry.md#RetryFunc)]
|
||||||
[[play](https://go.dev/play/p/nk2XRmagfVF)]
|
[[play](https://go.dev/play/p/nk2XRmagfVF)]
|
||||||
- **<big>RetryDuration</big>** : 设置重试间隔时间,默认 3 秒。
|
|
||||||
[[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/retry.md#RetryDuration)]
|
|
||||||
[[play](https://go.dev/play/p/nk2XRmagfVF)]
|
|
||||||
- **<big>RetryTimes</big>** : 设置重试次数,默认 5。
|
- **<big>RetryTimes</big>** : 设置重试次数,默认 5。
|
||||||
[[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/retry.md#RetryTimes)]
|
[[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/retry.md#RetryTimes)]
|
||||||
[[play](https://go.dev/play/p/ssfVeU2SwLO)]
|
[[play](https://go.dev/play/p/ssfVeU2SwLO)]
|
||||||
|
|||||||
@@ -70,7 +70,7 @@ func main() {
|
|||||||
return errors.New("error occurs")
|
return errors.New("error occurs")
|
||||||
}
|
}
|
||||||
|
|
||||||
duration := retry.RetryDuration(time.Microsecond*50)
|
duration := retry.RetryWithLinearBackoff(time.Microsecond*50)
|
||||||
|
|
||||||
retry.Retry(increaseNumber,
|
retry.Retry(increaseNumber,
|
||||||
duration,
|
duration,
|
||||||
@@ -116,7 +116,7 @@ func main() {
|
|||||||
return errors.New("error occurs")
|
return errors.New("error occurs")
|
||||||
}
|
}
|
||||||
|
|
||||||
duration := retry.RetryDuration(time.Microsecond*50)
|
duration := retry.RetryWithLinearBackoff(time.Microsecond*50)
|
||||||
|
|
||||||
err := retry.Retry(increaseNumber, duration)
|
err := retry.Retry(increaseNumber, duration)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -173,52 +173,6 @@ func main() {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
### <span id="RetryDuration">RetryDuration</span>
|
|
||||||
|
|
||||||
<p>设置重试间隔时间,默认3秒</p>
|
|
||||||
|
|
||||||
<b>函数签名:</b>
|
|
||||||
|
|
||||||
```go
|
|
||||||
func RetryDuration(d time.Duration)
|
|
||||||
```
|
|
||||||
|
|
||||||
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/nk2XRmagfVF)</span></b>
|
|
||||||
|
|
||||||
```go
|
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"errors"
|
|
||||||
"log"
|
|
||||||
"github.com/duke-git/lancet/v2/retry"
|
|
||||||
)
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
number := 0
|
|
||||||
increaseNumber := func() error {
|
|
||||||
number++
|
|
||||||
if number == 3 {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
return errors.New("error occurs")
|
|
||||||
}
|
|
||||||
|
|
||||||
duration := retry.RetryDuration(time.Microsecond*50)
|
|
||||||
|
|
||||||
err := retry.Retry(increaseNumber, duration)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
fmt.Println(number)
|
|
||||||
|
|
||||||
// Output:
|
|
||||||
// 3
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
### <span id="Retry">Retry</span>
|
### <span id="Retry">Retry</span>
|
||||||
|
|
||||||
<p>重试执行函数retryFunc,直到函数运行成功,或被context停止</p>
|
<p>重试执行函数retryFunc,直到函数运行成功,或被context停止</p>
|
||||||
@@ -251,7 +205,7 @@ func main() {
|
|||||||
return errors.New("error occurs")
|
return errors.New("error occurs")
|
||||||
}
|
}
|
||||||
|
|
||||||
duration := retry.RetryDuration(time.Microsecond*50)
|
duration := retry.RetryWithLinearBackoff(time.Microsecond*50)
|
||||||
|
|
||||||
err := retry.Retry(increaseNumber, duration)
|
err := retry.Retry(increaseNumber, duration)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user