瀏覽代碼

fix: adjust delay check concurrency

GyDi 2 年之前
父節點
當前提交
2bcf6fb3eb
共有 2 個文件被更改,包括 7 次插入16 次删除
  1. 2 2
      src/components/proxy/proxy-groups.tsx
  2. 5 14
      src/services/delay.ts

+ 2 - 2
src/components/proxy/proxy-groups.tsx

@@ -9,10 +9,10 @@ import {
 } from "@/services/api";
 import { useProfiles } from "@/hooks/use-profiles";
 import { useVerge } from "@/hooks/use-verge";
+import { BaseEmpty } from "../base";
 import { useRenderList } from "./use-render-list";
 import { ProxyRender } from "./proxy-render";
 import delayManager from "@/services/delay";
-import { BaseEmpty } from "../base";
 
 interface Props {
   mode: string;
@@ -83,7 +83,7 @@ export const ProxyGroups = (props: Props) => {
     }
 
     const names = proxies.filter((p) => !p!.provider).map((p) => p!.name);
-    await delayManager.checkListDelay(names, groupName, 24);
+    await delayManager.checkListDelay(names, groupName);
 
     onProxies();
   });

+ 5 - 14
src/services/delay.ts

@@ -84,35 +84,26 @@ class DelayManager {
     return delay;
   }
 
-  async checkListDelay(
-    nameList: readonly string[],
-    groupName: string,
-    concurrency: number
-  ) {
-    const names = [...nameList];
+  async checkListDelay(nameList: string[], group: string, concurrency = 6) {
+    const names = nameList.filter(Boolean);
+    // 设置正在延迟测试中
+    names.forEach((name) => this.setDelay(name, group, -2));
 
     let total = names.length;
     let current = 0;
 
-    // 设置正在延迟测试中
-    names.forEach((name) => this.setDelay(name, groupName, -2));
-
     return new Promise((resolve) => {
       const help = async (): Promise<void> => {
         if (current >= concurrency) return;
-
         const task = names.shift();
         if (!task) return;
-
         current += 1;
-        await this.checkDelay(task, groupName);
+        await this.checkDelay(task, group);
         current -= 1;
         total -= 1;
-
         if (total <= 0) resolve(null);
         else return help();
       };
-
       for (let i = 0; i < concurrency; ++i) help();
     });
   }