Files
certd/packages/core/basic/src/utils/util.lock.ts
T

18 lines
413 B
TypeScript
Raw Normal View History

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