fix: adjust delay check concurrency

This commit is contained in:
GyDi 2022-12-15 12:23:57 +08:00
parent d1ba0ed2b2
commit 2bcf6fb3eb
No known key found for this signature in database
GPG Key ID: 9C3AD40F1F99880A
2 changed files with 7 additions and 16 deletions

View File

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

View File

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