feat: promise race for long requests

This commit is contained in:
Nevo David 2025-08-07 23:33:55 +07:00
parent 3197c69f19
commit 0d231545ec
1 changed files with 10 additions and 8 deletions

View File

@ -19,17 +19,19 @@ export const concurrency = async <T>(
maxConcurrent,
datastore: 'ioredis',
connection,
minTime: 1000,
});
let load: T;
try {
load = await mapper[strippedIdentifier].schedule<T>(
{ expiration: 120_000 },
async () => {
const res = await func();
await timer(1000);
return res;
}
);
load = await mapper[strippedIdentifier].schedule<T>(async () => {
return await Promise.race<T>([
new Promise<T>(async (res) => {
await timer(300000);
res(true as T);
}),
func(),
]);
});
} catch (err) {}
return load;