@nickyzj2023/utils 1.0.33 → 1.0.34

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/function.ts CHANGED
@@ -15,22 +15,22 @@
15
15
  * ),
16
16
  */
17
17
  export const loopUntil = async <T>(
18
- fn: (count: number) => Promise<T>,
19
- options?: {
20
- /** 最大循环次数,默认 5 次 */
21
- maxRetries?: number;
22
- /** 停止循环条件,默认立即停止 */
23
- shouldStop?: (result: T) => boolean;
24
- },
18
+ fn: (count: number) => Promise<T>,
19
+ options?: {
20
+ /** 最大循环次数,默认 5 次 */
21
+ maxRetries?: number;
22
+ /** 停止循环条件,默认立即停止 */
23
+ shouldStop?: (result: T) => boolean;
24
+ },
25
25
  ): Promise<T> => {
26
- const { maxRetries = 5, shouldStop = () => true } = options ?? {};
26
+ const { maxRetries = 5, shouldStop = () => true } = options ?? {};
27
27
 
28
- for (let i = 0; i < maxRetries; i++) {
29
- const result = await fn(i);
30
- if (shouldStop(result)) {
31
- return result;
32
- }
33
- }
28
+ for (let i = 0; i < maxRetries; i++) {
29
+ const result = await fn(i);
30
+ if (shouldStop(result)) {
31
+ return result;
32
+ }
33
+ }
34
34
 
35
- throw new Error("超过了最大循环次数(maxRetires)且未满足停止执行条件");
35
+ throw new Error(`超过了最大循环次数(${maxRetries})且未满足停止执行条件`);
36
36
  };