@nathapp/nestjs-redis 1.3.4 → 1.3.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -11,4 +11,5 @@ export declare class RedisLockService implements OnApplicationShutdown {
11
11
  onApplicationShutdown(signal?: string): Promise<void>;
12
12
  acquireLock(name: string, expiryMs?: number): Promise<void>;
13
13
  releaseLock(name: string): Promise<void>;
14
+ withLock<T = any>(name: string, runWithLock: () => Promise<T>, expiryMs?: number): Promise<T>;
14
15
  }
@@ -54,6 +54,18 @@ let RedisLockService = RedisLockService_1 = class RedisLockService {
54
54
  }
55
55
  }
56
56
  }
57
+ async withLock(name, runWithLock, expiryMs = 60000) {
58
+ await this.acquireLock(name, expiryMs);
59
+ try {
60
+ return await runWithLock();
61
+ }
62
+ catch (error) {
63
+ throw error;
64
+ }
65
+ finally {
66
+ await this.releaseLock(name);
67
+ }
68
+ }
57
69
  };
58
70
  RedisLockService = RedisLockService_1 = __decorate([
59
71
  (0, common_1.Injectable)(),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nathapp/nestjs-redis",
3
- "version": "1.3.4",
3
+ "version": "1.3.5",
4
4
  "description": "a NestJS ioRedis module",
5
5
  "author": "skunight",
6
6
  "license": "MIT",