import { ioRedis } from '@gitroom/nestjs-libraries/redis/redis.service'; import Bottleneck from 'bottleneck'; const connection = new Bottleneck.IORedisConnection({ client: ioRedis, }); const bottleneck = new Bottleneck.Group({ maxConcurrent: 1, datastore: 'ioredis', connection, }); export async function concurrencyService( identifier: string, func: (...args: any[]) => Promise ): Promise { let load: T; try { load = await bottleneck .key(identifier.split('-')[0]) .schedule({ expiration: 60_000 }, async () => { return await func(); }); } catch (err) {} return load; }