From 0d231545ecd4789b11abfe96b46ea5e63929ef84 Mon Sep 17 00:00:00 2001 From: Nevo David Date: Thu, 7 Aug 2025 23:33:55 +0700 Subject: [PATCH] feat: promise race for long requests --- .../helpers/src/utils/concurrency.service.ts | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/libraries/helpers/src/utils/concurrency.service.ts b/libraries/helpers/src/utils/concurrency.service.ts index c92b3915..99ee82fa 100644 --- a/libraries/helpers/src/utils/concurrency.service.ts +++ b/libraries/helpers/src/utils/concurrency.service.ts @@ -19,17 +19,19 @@ export const concurrency = async ( maxConcurrent, datastore: 'ioredis', connection, + minTime: 1000, }); let load: T; try { - load = await mapper[strippedIdentifier].schedule( - { expiration: 120_000 }, - async () => { - const res = await func(); - await timer(1000); - return res; - } - ); + load = await mapper[strippedIdentifier].schedule(async () => { + return await Promise.race([ + new Promise(async (res) => { + await timer(300000); + res(true as T); + }), + func(), + ]); + }); } catch (err) {} return load;