mirror of
https://github.com/SukkaW/Surge.git
synced 2025-12-12 01:00:34 +08:00
Chore: timeout properly
This commit is contained in:
parent
48b3c4538e
commit
6ed3695e36
@ -141,65 +141,62 @@ export const buildSpeedtestDomainSet = task(import.meta.path, async () => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let timer;
|
await new Promise<void>((resolve) => {
|
||||||
|
const pMap = ([
|
||||||
const pMap = ([
|
'Hong Kong',
|
||||||
'Hong Kong',
|
'Taiwan',
|
||||||
'Taiwan',
|
'China Telecom',
|
||||||
'China Telecom',
|
'China Mobile',
|
||||||
'China Mobile',
|
'China Unicom',
|
||||||
'China Unicom',
|
'Japan',
|
||||||
'Japan',
|
'Tokyo',
|
||||||
'Tokyo',
|
'Singapore',
|
||||||
'Singapore',
|
'Korea',
|
||||||
'Korea',
|
'Canada',
|
||||||
'Canada',
|
'Toronto',
|
||||||
'Toronto',
|
'Montreal',
|
||||||
'Montreal',
|
'Los Ang',
|
||||||
'Los Ang',
|
'San Jos',
|
||||||
'San Jos',
|
'Seattle',
|
||||||
'Seattle',
|
'New York',
|
||||||
'New York',
|
'Dallas',
|
||||||
'Dallas',
|
'Miami',
|
||||||
'Miami',
|
'Berlin',
|
||||||
'Berlin',
|
'Frankfurt',
|
||||||
'Frankfurt',
|
'London',
|
||||||
'London',
|
'Paris',
|
||||||
'Paris',
|
'Amsterdam',
|
||||||
'Amsterdam',
|
'Moscow',
|
||||||
'Moscow',
|
'Australia',
|
||||||
'Australia',
|
'Sydney',
|
||||||
'Sydney',
|
'Brazil',
|
||||||
'Brazil',
|
'Turkey'
|
||||||
'Turkey'
|
]).reduce<Record<string, Promise<void>>>((pMap, keyword) => {
|
||||||
]).reduce<Record<string, Promise<void>>>((pMap, keyword) => {
|
pMap[keyword] = querySpeedtestApi(keyword).then(hostnameGroup => {
|
||||||
pMap[keyword] = querySpeedtestApi(keyword).then(hostnameGroup => {
|
hostnameGroup.forEach(hostname => {
|
||||||
hostnameGroup.forEach(hostname => {
|
if (hostname) {
|
||||||
if (hostname) {
|
domains.add(hostname);
|
||||||
domains.add(hostname);
|
}
|
||||||
}
|
});
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
|
||||||
return pMap;
|
return pMap;
|
||||||
}, {});
|
}, {});
|
||||||
|
|
||||||
try {
|
const timer = setTimeout(() => {
|
||||||
timer = setTimeout(() => {
|
|
||||||
console.error(picocolors.red('Task timeout!'));
|
console.error(picocolors.red('Task timeout!'));
|
||||||
Object.entries(pMap).forEach(([name, p]) => {
|
Object.entries(pMap).forEach(([name, p]) => {
|
||||||
console.log(`[${name}]`, Bun.peek.status(p));
|
console.log(`[${name}]`, Bun.peek.status(p));
|
||||||
});
|
});
|
||||||
|
|
||||||
throw new Error('timeout');
|
resolve();
|
||||||
}, 1000 * 60 * 2);
|
}, 1000 * 60 * 2);
|
||||||
|
|
||||||
await Promise.all(Object.values(pMap));
|
Promise.all(Object.values(pMap)).then(() => {
|
||||||
} finally {
|
|
||||||
if (timer) {
|
|
||||||
clearTimeout(timer);
|
clearTimeout(timer);
|
||||||
}
|
resolve();
|
||||||
}
|
});
|
||||||
|
});
|
||||||
|
|
||||||
const gorhill = await getGorhillPublicSuffixPromise();
|
const gorhill = await getGorhillPublicSuffixPromise();
|
||||||
const deduped = sortDomains(domainDeduper(Array.from(domains)), gorhill);
|
const deduped = sortDomains(domainDeduper(Array.from(domains)), gorhill);
|
||||||
|
|||||||
@ -102,6 +102,9 @@ import type { TaskResult } from './lib/trace-runner';
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
printStats(stats);
|
printStats(stats);
|
||||||
|
|
||||||
|
// Finish the build to avoid leaking timer/fetch ref
|
||||||
|
process.exit(0);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.trace(e);
|
console.trace(e);
|
||||||
console.error('Something went wrong!');
|
console.error('Something went wrong!');
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user