From a75cda4deb40b534be3679984ec1f67ef0d32e3c Mon Sep 17 00:00:00 2001 From: GitHub Actions Date: Wed, 8 May 2024 09:57:38 +0000 Subject: [PATCH] Update api docs --- docs/api/x.md | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/docs/api/x.md b/docs/api/x.md index 0d0d37a67..f70d5b87d 100755 --- a/docs/api/x.md +++ b/docs/api/x.md @@ -27,6 +27,7 @@ | [x.Range](#range) || | [x.Reduce](#reduce) || | [x.RemoveRepeat](#removerepeat) |Uniq creates an array with unique values. | +| [x.Retry](#retry) |retry 对第二个参数作为函数的情况,重试N次,如果第二个参数返回值是 true,则重试,否则就结束,如果遇到错误,停止重试 | | [x.Reverse](#reverse) |Reverse transforms an array the first element will become the last, the second element will become the second to last, etc. | | [x.Shift](#shift) || | [x.Shuffle](#shuffle) |Shuffle creates an array of shuffled values | @@ -568,6 +569,71 @@ Uniq creates an array with unique values. | r1 | `any` | | +### Retry + +#### 详细描述 +retry 对第二个参数作为函数的情况,重试N次,如果第二个参数返回值是 true,则重试,否则就结束,如果遇到错误,停止重试 + +Example: +``` +count = 0 + + retry(100, () => { + defer recover() + + count++ + if count > 3 { + die(111) + } + return true + }) + +assert count == 4, f`${count}` + +count = 0 + + retry(100, () => { + defer recover() + + count++ + if count > 3 { + return false + } + return true + }) + +assert count == 4, f`${count}` + +count = 0 + + retry(100, () => { + count++ + }) + +assert count == 1, f`${count}` + +count = 0 + + retry(100, () => { + count++ + return true + }) + +assert count == 100, f`${count}` +``` + + +#### 定义 + +`Retry(i int, handler func() bool)` + +#### 参数 +|参数名|参数类型|参数解释| +|:-----------|:---------- |:-----------| +| i | `int` | | +| handler | `func() bool` | | + + ### Reverse #### 详细描述