@zwa73/utils 1.0.188 → 1.0.189

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.
@@ -188,7 +188,7 @@ class UtilFunc {
188
188
  //根据最大重试次数限制进行循环
189
189
  for (let i = 0; i < count;) {
190
190
  if (i > 0 && opt.tryDelay)
191
- await this.sleep(opt.tryDelay);
191
+ await UtilFunc.sleep(opt.tryDelay);
192
192
  UtilLogger_1.SLogger.info(`开始第 ${i + 1} 次 repeatPromise`);
193
193
  //如果 plist 中当前下标的任务还未创建 则 创建当前任务
194
194
  if (plist.length < i + 1) {
@@ -396,11 +396,12 @@ class UtilFunc {
396
396
  */
397
397
  static queueProc(flag, task) {
398
398
  // 如果当前标签的队列不存在,则创建一个新的队列
399
- if (!this.pendingMap[flag])
400
- this.pendingMap[flag] = [];
399
+ if (!UtilFunc.pendingMap[flag])
400
+ UtilFunc.pendingMap[flag] = [];
401
401
  // 创建一个新的Promise,并保存resolve函数以便后续调用
402
402
  let resolveFunc;
403
- const promise = new Promise((resolve) => {
403
+ let rejectFunc;
404
+ const promise = new Promise((resolve, reject) => {
404
405
  resolveFunc = resolve;
405
406
  });
406
407
  // 定义处理任务的函数
@@ -414,25 +415,26 @@ class UtilFunc {
414
415
  }
415
416
  catch (error) {
416
417
  // 如果任务执行出错,记录错误日志
417
- UtilLogger_1.SLogger.warn(`queueProc 错误: `, error, `flag: ${String(flag)}`);
418
+ UtilLogger_1.SLogger.warn(`queueProc 错误 flag: ${String(flag)} 已抛出`);
419
+ rejectFunc(error);
418
420
  }
419
421
  finally {
420
422
  // 无论任务是否成功,都从队列中移除当前任务
421
- this.pendingMap[flag].shift();
423
+ UtilFunc.pendingMap[flag].shift();
422
424
  // 如果队列中还有任务,执行下一个任务
423
- if (this.pendingMap[flag].length > 0) {
424
- this.pendingMap[flag][0]();
425
+ if (UtilFunc.pendingMap[flag].length > 0) {
426
+ UtilFunc.pendingMap[flag][0]();
425
427
  }
426
428
  else {
427
429
  // 如果队列中没有任务,删除队列
428
- delete this.pendingMap[flag];
430
+ delete UtilFunc.pendingMap[flag];
429
431
  }
430
432
  }
431
433
  };
432
434
  // 将处理任务的函数添加到队列中
433
- this.pendingMap[flag].push(processTask);
435
+ UtilFunc.pendingMap[flag].push(processTask);
434
436
  // 如果队列中只有当前任务,立即执行
435
- if (this.pendingMap[flag].length === 1)
437
+ if (UtilFunc.pendingMap[flag].length === 1)
436
438
  processTask();
437
439
  // 返回Promise,以便调用者可以等待任务完成
438
440
  return promise;
@@ -441,7 +443,7 @@ class UtilFunc {
441
443
  * @param flag - 队列标签
442
444
  */
443
445
  static queueLength(flag) {
444
- const pd = this.pendingMap[flag];
446
+ const pd = UtilFunc.pendingMap[flag];
445
447
  return pd != null ? pd.length : 0;
446
448
  }
447
449
  /**创建一个Outcome */
@@ -728,7 +730,10 @@ class UtilFunc {
728
730
  static parseSrtTime(time) {
729
731
  const [hours, minutes, seconds] = time.split(':');
730
732
  const [secs, milliseconds] = seconds.split(',');
731
- return parseInt(hours) * 3600000 + parseInt(minutes) * 60000 + parseInt(secs) * 1000 + parseInt(milliseconds);
733
+ return parseInt(hours) * 3600000 +
734
+ parseInt(minutes) * 60000 +
735
+ parseInt(secs) * 1000 +
736
+ parseInt(milliseconds);
732
737
  }
733
738
  /**将毫秒转换为hh:mm:ss,ms格式 */
734
739
  static formatSrtTime(milliseconds) {
@@ -748,7 +753,8 @@ class UtilFunc {
748
753
  if (!id)
749
754
  continue;
750
755
  const timeRange = srtLines[index++].trim();
751
- const [start, end] = timeRange.split(' --> ').map(time => UtilFunc.parseSrtTime(time));
756
+ const [start, end] = timeRange.split(' --> ')
757
+ .map(time => UtilFunc.parseSrtTime(time));
752
758
  let text = '';
753
759
  while (index < srtLines.length && srtLines[index].trim())
754
760
  text += `${srtLines[index++]}\n`;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zwa73/utils",
3
- "version": "1.0.188",
3
+ "version": "1.0.189",
4
4
  "description": "my utils",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -249,7 +249,7 @@ Promise<RepeatPromiseResult<T>>{
249
249
  try{
250
250
  //根据最大重试次数限制进行循环
251
251
  for(let i=0;i<count;){
252
- if(i>0 && opt.tryDelay) await this.sleep(opt.tryDelay);
252
+ if(i>0 && opt.tryDelay) await UtilFunc.sleep(opt.tryDelay);
253
253
  SLogger.info(`开始第 ${i+1} 次 repeatPromise`);
254
254
  //如果 plist 中当前下标的任务还未创建 则 创建当前任务
255
255
  if(plist.length<i+1){
@@ -468,11 +468,12 @@ static pendingMap:Record<Keyable,AnyFunc[]> = {};
468
468
  */
469
469
  static queueProc<T>(flag: Keyable, task: () => Promise<T>): Promise<T> {
470
470
  // 如果当前标签的队列不存在,则创建一个新的队列
471
- if (!this.pendingMap[flag]) this.pendingMap[flag] = [];
471
+ if (!UtilFunc.pendingMap[flag]) UtilFunc.pendingMap[flag] = [];
472
472
 
473
473
  // 创建一个新的Promise,并保存resolve函数以便后续调用
474
474
  let resolveFunc: (value: T | PromiseLike<T>) => void;
475
- const promise = new Promise<T>((resolve) => {
475
+ let rejectFunc: (value: any | PromiseLike<any>) => void;
476
+ const promise = new Promise<T>((resolve,reject) => {
476
477
  resolveFunc = resolve;
477
478
  });
478
479
 
@@ -486,24 +487,25 @@ static queueProc<T>(flag: Keyable, task: () => Promise<T>): Promise<T> {
486
487
  resolveFunc(result);
487
488
  } catch (error) {
488
489
  // 如果任务执行出错,记录错误日志
489
- SLogger.warn(`queueProc 错误: `,error,`flag: ${String(flag)}`);
490
+ SLogger.warn(`queueProc 错误 flag: ${String(flag)} 已抛出`);
491
+ rejectFunc(error);
490
492
  } finally {
491
493
  // 无论任务是否成功,都从队列中移除当前任务
492
- this.pendingMap[flag].shift();
494
+ UtilFunc.pendingMap[flag].shift();
493
495
  // 如果队列中还有任务,执行下一个任务
494
- if (this.pendingMap[flag].length > 0) {
495
- this.pendingMap[flag][0]();
496
+ if (UtilFunc.pendingMap[flag].length > 0) {
497
+ UtilFunc.pendingMap[flag][0]();
496
498
  } else {
497
499
  // 如果队列中没有任务,删除队列
498
- delete this.pendingMap[flag];
500
+ delete UtilFunc.pendingMap[flag];
499
501
  }
500
502
  }
501
503
  };
502
504
 
503
505
  // 将处理任务的函数添加到队列中
504
- this.pendingMap[flag].push(processTask);
506
+ UtilFunc.pendingMap[flag].push(processTask);
505
507
  // 如果队列中只有当前任务,立即执行
506
- if (this.pendingMap[flag].length === 1) processTask();
508
+ if (UtilFunc.pendingMap[flag].length === 1) processTask();
507
509
 
508
510
  // 返回Promise,以便调用者可以等待任务完成
509
511
  return promise;
@@ -512,7 +514,7 @@ static queueProc<T>(flag: Keyable, task: () => Promise<T>): Promise<T> {
512
514
  * @param flag - 队列标签
513
515
  */
514
516
  static queueLength(flag:Keyable){
515
- const pd = this.pendingMap[flag]
517
+ const pd = UtilFunc.pendingMap[flag]
516
518
  return pd!=null ? pd.length : 0;
517
519
  }
518
520
 
@@ -861,7 +863,10 @@ static parseSrtTime(time: string): number {
861
863
  const [hours, minutes, seconds] = time.split(':');
862
864
  const [secs, milliseconds] = seconds.split(',');
863
865
 
864
- return parseInt(hours) * 3600000 + parseInt(minutes) * 60000 + parseInt(secs) * 1000 + parseInt(milliseconds);
866
+ return parseInt(hours) * 3600000 +
867
+ parseInt(minutes) * 60000 +
868
+ parseInt(secs) * 1000 +
869
+ parseInt(milliseconds);
865
870
  }
866
871
  /**将毫秒转换为hh:mm:ss,ms格式 */
867
872
  static formatSrtTime(milliseconds: number): string {
@@ -883,7 +888,8 @@ static parseSrt(srtText: string): SrtSegment[] {
883
888
  if (!id) continue;
884
889
 
885
890
  const timeRange = srtLines[index++].trim();
886
- const [start, end] = timeRange.split(' --> ').map(time => UtilFunc.parseSrtTime(time));
891
+ const [start, end] = timeRange.split(' --> ')
892
+ .map(time => UtilFunc.parseSrtTime(time));
887
893
 
888
894
  let text = '';
889
895
  while (index < srtLines.length && srtLines[index].trim())