Files
certd/packages/core/basic/src/utils/util.lock.ts
2025-11-29 03:25:21 +08:00

18 lines
413 B
TypeScript

// @ts-ignore
import AsyncLock from "async-lock";
export class Locker {
private asyncLocker: AsyncLock;
constructor() {
this.asyncLocker = new AsyncLock();
}
async execute(lockStr: string, callback: any, options?: { timeout?: number }) {
const timeout = options?.timeout ?? 120000;
return this.asyncLocker.acquire(lockStr, callback, { timeout });
}
}
export const locker = new Locker();