From 33a49cba4a3b26902148eecdd20d58d460f7b2ff Mon Sep 17 00:00:00 2001 From: HorizonCode Date: Fri, 10 Jan 2025 01:19:55 +0100 Subject: [PATCH] make MutexOptions optional --- src/MutexLock.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/MutexLock.ts b/src/MutexLock.ts index 835abd1..39aad97 100644 --- a/src/MutexLock.ts +++ b/src/MutexLock.ts @@ -9,9 +9,9 @@ type RedisClient = redis.RedisClientType< export class MutexLock { redisClient: RedisClient; - mutexOptions: MutexOptions; + mutexOptions: MutexOptions | undefined; - constructor(redisClient: RedisClient, options: MutexOptions) { + constructor(redisClient: RedisClient, options?: MutexOptions) { this.mutexOptions = options; this.redisClient = redisClient; } @@ -19,7 +19,7 @@ export class MutexLock { static async create(options: MutexOptions) { const redisClient = await redis .createClient({ - url: `redis://${options.redis?.host ?? "127.0.0.1"}:${options.redis?.port ?? 6379}`, + url: `redis://${options?.redis?.host ?? "127.0.0.1"}:${options?.redis?.port ?? 6379}`, }) .connect(); @@ -40,12 +40,12 @@ export class MutexLock { if (acquired) { await this.redisClient.expire( lockIdentifier, - this.mutexOptions.mutex?.ttl || 60 + this.mutexOptions?.mutex?.ttl || 60 ); return releaseFunc; } await new Promise(resolve => - setTimeout(resolve, this.mutexOptions.mutex?.checkInterval || 100) + setTimeout(resolve, this.mutexOptions?.mutex?.checkInterval || 100) ); } }}