@zwa73/utils 1.0.183 → 1.0.185
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/dist/UtilCom.d.ts +4 -4
- package/dist/UtilFunctions.d.ts +4 -4
- package/dist/UtilFunctions.js +23 -5
- package/package.json +1 -1
- package/src/UtilFunctions.ts +24 -8
package/dist/UtilCom.d.ts
CHANGED
|
@@ -110,7 +110,7 @@ export declare namespace UtilCom {
|
|
|
110
110
|
headers: http.IncomingHttpHeaders;
|
|
111
111
|
/**响应状态码 */
|
|
112
112
|
statusCode?: number;
|
|
113
|
-
} | undefined
|
|
113
|
+
} | undefined>>;
|
|
114
114
|
/**重复一个 http POST请求并接受数据
|
|
115
115
|
* @async
|
|
116
116
|
* @param comReqOpt - 网络请求选项
|
|
@@ -125,7 +125,7 @@ export declare namespace UtilCom {
|
|
|
125
125
|
headers: http.IncomingHttpHeaders;
|
|
126
126
|
/**响应状态码 */
|
|
127
127
|
statusCode?: number;
|
|
128
|
-
} | undefined
|
|
128
|
+
} | undefined>>;
|
|
129
129
|
/**重复一个 https GET 请求并接受数据
|
|
130
130
|
* @async
|
|
131
131
|
* @param comReqOpt - 网络请求选项
|
|
@@ -140,7 +140,7 @@ export declare namespace UtilCom {
|
|
|
140
140
|
headers: http.IncomingHttpHeaders;
|
|
141
141
|
/**响应状态码 */
|
|
142
142
|
statusCode?: number;
|
|
143
|
-
} | undefined
|
|
143
|
+
} | undefined>>;
|
|
144
144
|
/**重复一个 http GET 请求并接受数据
|
|
145
145
|
* @async
|
|
146
146
|
* @param comReqOpt - 网络请求选项
|
|
@@ -155,5 +155,5 @@ export declare namespace UtilCom {
|
|
|
155
155
|
headers: http.IncomingHttpHeaders;
|
|
156
156
|
/**响应状态码 */
|
|
157
157
|
statusCode?: number;
|
|
158
|
-
} | undefined
|
|
158
|
+
} | undefined>>;
|
|
159
159
|
}
|
package/dist/UtilFunctions.d.ts
CHANGED
|
@@ -34,9 +34,9 @@ type SuccessOut<T> = Outcome<Success, T>;
|
|
|
34
34
|
type TimeoutOut<T> = Outcome<Timeout, Promise<T>>;
|
|
35
35
|
/**完成的重试请求 */
|
|
36
36
|
export type RepeatPromiseResult<T> = {
|
|
37
|
-
completed: T;
|
|
37
|
+
completed: T | undefined;
|
|
38
38
|
/**还未完成的其他Promise 若是验证失败则会返回undefined */
|
|
39
|
-
pending
|
|
39
|
+
pending: Promise<T | undefined>[];
|
|
40
40
|
};
|
|
41
41
|
/**遍历对象的回调函数
|
|
42
42
|
* @param key - 字段名
|
|
@@ -111,9 +111,9 @@ export declare class UtilFunc {
|
|
|
111
111
|
* @param procFn - 发起函数
|
|
112
112
|
* @param verifyFn - 验证函数
|
|
113
113
|
* @param opt - 重试参数 默认 延迟:0ms 间隔:180_000ms 重试:3次
|
|
114
|
-
* @returns
|
|
114
|
+
* @returns 重复结果
|
|
115
115
|
*/
|
|
116
|
-
static repeatPromise<T>(procFn: () => Promise<T>, verifyFn?: ReqVerifyFn<T>, opt?: RepeatPromiseOpt): Promise<RepeatPromiseResult<T
|
|
116
|
+
static repeatPromise<T>(procFn: () => Promise<T>, verifyFn?: ReqVerifyFn<T>, opt?: RepeatPromiseOpt): Promise<RepeatPromiseResult<T>>;
|
|
117
117
|
/**创建一个限时的Promise
|
|
118
118
|
* @param func - 处理函数
|
|
119
119
|
* @param timeLimit - 毫秒限时
|
package/dist/UtilFunctions.js
CHANGED
|
@@ -170,7 +170,7 @@ class UtilFunc {
|
|
|
170
170
|
* @param procFn - 发起函数
|
|
171
171
|
* @param verifyFn - 验证函数
|
|
172
172
|
* @param opt - 重试参数 默认 延迟:0ms 间隔:180_000ms 重试:3次
|
|
173
|
-
* @returns
|
|
173
|
+
* @returns 重复结果
|
|
174
174
|
*/
|
|
175
175
|
static async repeatPromise(procFn, verifyFn, opt = {}) {
|
|
176
176
|
opt.count = opt.count ?? 3;
|
|
@@ -262,13 +262,31 @@ class UtilFunc {
|
|
|
262
262
|
}),
|
|
263
263
|
};
|
|
264
264
|
}
|
|
265
|
-
//全部失败或超时则返回
|
|
265
|
+
//全部失败或超时则返回 全pending
|
|
266
266
|
UtilLogger_1.SLogger.warn(`${count} 次 repeatPromise 尝试均失败`);
|
|
267
|
-
return
|
|
267
|
+
return {
|
|
268
|
+
completed: undefined,
|
|
269
|
+
pending: plist
|
|
270
|
+
.filter(p => p != UtilFunc.getNeverResolvedPromise())
|
|
271
|
+
.map(async (p) => {
|
|
272
|
+
const curObj = await p;
|
|
273
|
+
if (curObj.status == UtilSymbol_1.Success) {
|
|
274
|
+
const outres = curObj.result;
|
|
275
|
+
if (outres.stat == UtilSymbol_1.Success)
|
|
276
|
+
return outres.result;
|
|
277
|
+
}
|
|
278
|
+
if (curObj.status == UtilSymbol_1.Timeout) {
|
|
279
|
+
const outres = await curObj.result;
|
|
280
|
+
if (outres.stat == UtilSymbol_1.Success)
|
|
281
|
+
return outres.result;
|
|
282
|
+
}
|
|
283
|
+
return undefined;
|
|
284
|
+
}),
|
|
285
|
+
};
|
|
268
286
|
}
|
|
269
287
|
catch (err) {
|
|
270
|
-
UtilLogger_1.SLogger.warn(`repeatPromise
|
|
271
|
-
return undefined;
|
|
288
|
+
UtilLogger_1.SLogger.warn(`repeatPromise 发生意外错误`, err);
|
|
289
|
+
return { completed: undefined, pending: [] };
|
|
272
290
|
}
|
|
273
291
|
}
|
|
274
292
|
/**创建一个限时的Promise
|
package/package.json
CHANGED
package/src/UtilFunctions.ts
CHANGED
|
@@ -58,9 +58,9 @@ type PromiseResult<T> = {
|
|
|
58
58
|
|
|
59
59
|
/**完成的重试请求 */
|
|
60
60
|
export type RepeatPromiseResult<T> = {
|
|
61
|
-
completed:T;
|
|
61
|
+
completed:T|undefined;
|
|
62
62
|
/**还未完成的其他Promise 若是验证失败则会返回undefined */
|
|
63
|
-
pending
|
|
63
|
+
pending:Promise<T|undefined>[];
|
|
64
64
|
}
|
|
65
65
|
|
|
66
66
|
|
|
@@ -224,11 +224,11 @@ static getNeverResolvedPromise<T>():Promise<T>{
|
|
|
224
224
|
* @param procFn - 发起函数
|
|
225
225
|
* @param verifyFn - 验证函数
|
|
226
226
|
* @param opt - 重试参数 默认 延迟:0ms 间隔:180_000ms 重试:3次
|
|
227
|
-
* @returns
|
|
227
|
+
* @returns 重复结果
|
|
228
228
|
*/
|
|
229
229
|
@LogTimeAsync("repeatPromise ",true)
|
|
230
230
|
static async repeatPromise<T>(procFn:()=>Promise<T>,verifyFn?:ReqVerifyFn<T>,opt:RepeatPromiseOpt = {}):
|
|
231
|
-
Promise<RepeatPromiseResult<T
|
|
231
|
+
Promise<RepeatPromiseResult<T>>{
|
|
232
232
|
opt.count = opt.count??3;
|
|
233
233
|
opt.tryInterval = opt.tryInterval??180_000;
|
|
234
234
|
const {count,tryInterval} = opt;
|
|
@@ -323,12 +323,28 @@ Promise<RepeatPromiseResult<T>|undefined>{
|
|
|
323
323
|
}),
|
|
324
324
|
};
|
|
325
325
|
}
|
|
326
|
-
//全部失败或超时则返回
|
|
326
|
+
//全部失败或超时则返回 全pending
|
|
327
327
|
SLogger.warn(`${count} 次 repeatPromise 尝试均失败`);
|
|
328
|
-
return
|
|
328
|
+
return {
|
|
329
|
+
completed:undefined,
|
|
330
|
+
pending:plist
|
|
331
|
+
.filter(p=>p!=UtilFunc.getNeverResolvedPromise())
|
|
332
|
+
.map(async p=>{
|
|
333
|
+
const curObj = await p;
|
|
334
|
+
if(curObj.status==Success){
|
|
335
|
+
const outres = curObj.result;
|
|
336
|
+
if(outres.stat==Success) return outres.result;
|
|
337
|
+
}
|
|
338
|
+
if(curObj.status==Timeout){
|
|
339
|
+
const outres = await curObj.result;
|
|
340
|
+
if(outres.stat==Success) return outres.result;
|
|
341
|
+
}
|
|
342
|
+
return undefined;
|
|
343
|
+
}),
|
|
344
|
+
};
|
|
329
345
|
}catch(err){
|
|
330
|
-
SLogger.warn(`repeatPromise
|
|
331
|
-
return undefined;
|
|
346
|
+
SLogger.warn(`repeatPromise 发生意外错误`,err);
|
|
347
|
+
return {completed:undefined,pending:[]};
|
|
332
348
|
}
|
|
333
349
|
}
|
|
334
350
|
|