mirror of
https://github.com/certd/certd.git
synced 2026-04-05 07:20:56 +08:00
18 lines
413 B
TypeScript
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();
|