diff --git a/README_zh-CN.md b/README_zh-CN.md index a2613209..d8c27d3c 100644 --- a/README_zh-CN.md +++ b/README_zh-CN.md @@ -1200,9 +1200,6 @@ import "github.com/duke-git/lancet/v2/retry" - **RetryFunc** : 重试执行的函数。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/retry.md#RetryFunc)] [[play](https://go.dev/play/p/nk2XRmagfVF)] -- **RetryDuration** : 设置重试间隔时间,默认 3 秒。 - [[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/retry.md#RetryDuration)] - [[play](https://go.dev/play/p/nk2XRmagfVF)] - **RetryTimes** : 设置重试次数,默认 5。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/retry.md#RetryTimes)] [[play](https://go.dev/play/p/ssfVeU2SwLO)] diff --git a/docs/api/packages/retry.md b/docs/api/packages/retry.md index 1c065c29..165bd737 100644 --- a/docs/api/packages/retry.md +++ b/docs/api/packages/retry.md @@ -70,7 +70,7 @@ func main() { return errors.New("error occurs") } - duration := retry.RetryDuration(time.Microsecond*50) + duration := retry.RetryWithLinearBackoff(time.Microsecond*50) retry.Retry(increaseNumber, duration, @@ -116,7 +116,7 @@ func main() { return errors.New("error occurs") } - duration := retry.RetryDuration(time.Microsecond*50) + duration := retry.RetryWithLinearBackoff(time.Microsecond*50) err := retry.Retry(increaseNumber, duration) if err != nil { @@ -173,52 +173,6 @@ func main() { } ``` -### RetryDuration - -

设置重试间隔时间,默认3秒

- -函数签名: - -```go -func RetryDuration(d time.Duration) -``` - -示例:[运行](https://go.dev/play/p/nk2XRmagfVF) - -```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 -} -``` - ### Retry

重试执行函数retryFunc,直到函数运行成功,或被context停止

@@ -251,7 +205,7 @@ func main() { return errors.New("error occurs") } - duration := retry.RetryDuration(time.Microsecond*50) + duration := retry.RetryWithLinearBackoff(time.Microsecond*50) err := retry.Retry(increaseNumber, duration) if err != nil {