vault-link/frontend/obsidian-plugin/src/debugging/slow-fetch-factory.ts

14 lines
337 B
TypeScript

export const slowFetchFactory =
(jitterScaleInSeconds: number) =>
async (
input: string | URL | globalThis.Request,
init?: RequestInit
): Promise<Response> => {
if (jitterScaleInSeconds > 0) {
await sleep(Math.random() * jitterScaleInSeconds * 1000);
}
const response = await fetch(input, init);
return response;
};