export class LockManager { private locks: { [key: string]: Promise }; constructor() { this.locks = {}; } async acquireLock(key: string, task: () => Promise): Promise { if (!this.locks[key]) { this.locks[key] = new Promise(async (resolve, reject) => { try { const result = await task(); resolve(result); } catch (error) { reject(error); } finally { delete this.locks[key]; } }); } return await this.locks[key]; } }