mirror of
https://github.com/pezkuwichain/phishing.git
synced 2026-06-12 21:41:06 +00:00
Adjust addrcheck timeouts (jest 27) (#353)
This commit is contained in:
@@ -31,7 +31,12 @@ async function loopSome (site: string, matcher: () => Promise<string[] | null>):
|
||||
// console.error(error);
|
||||
}
|
||||
|
||||
await new Promise<boolean>((resolve) => setTimeout(() => resolve(true), Math.floor((Math.random() * 750) + 1000)));
|
||||
await new Promise<boolean>((resolve) =>
|
||||
setTimeout(
|
||||
() => resolve(true),
|
||||
Math.floor((Math.random() * 750) + 1000)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
return [site, found];
|
||||
|
||||
@@ -6,10 +6,25 @@ import { fetch } from '@polkadot/x-fetch';
|
||||
// a fetch with a 2s timeout
|
||||
export async function fetchWithTimeout (url: string, timeout = 2000): Promise<Response> {
|
||||
const controller = new AbortController();
|
||||
const id = setTimeout(() => controller.abort(), timeout);
|
||||
const response = await fetch(url, { signal: controller.signal });
|
||||
let isAborted = false;
|
||||
const id = setTimeout((): void => {
|
||||
console.log(`Timeout on ${url}`);
|
||||
|
||||
clearTimeout(id);
|
||||
isAborted = true;
|
||||
controller.abort();
|
||||
}, timeout);
|
||||
|
||||
return response;
|
||||
try {
|
||||
const response = await fetch(url, { signal: controller.signal });
|
||||
|
||||
clearTimeout(id);
|
||||
|
||||
return response;
|
||||
} catch (error) {
|
||||
if (!isAborted) {
|
||||
clearTimeout(id);
|
||||
}
|
||||
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user