@klapeks/micro-db-utils 0.0.8 → 0.0.9
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.
|
@@ -161,6 +161,33 @@ var RedisConnection = /** @class */ (function () {
|
|
|
161
161
|
});
|
|
162
162
|
});
|
|
163
163
|
};
|
|
164
|
+
RedisConnection.prototype.autoLock = function (key, fn, options) {
|
|
165
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
166
|
+
var isAlreadyLocked, err_3;
|
|
167
|
+
return __generator(this, function (_a) {
|
|
168
|
+
switch (_a.label) {
|
|
169
|
+
case 0: return [4 /*yield*/, this.setLock(key, options)];
|
|
170
|
+
case 1:
|
|
171
|
+
isAlreadyLocked = (_a.sent()).isAlreadyLocked;
|
|
172
|
+
if (isAlreadyLocked)
|
|
173
|
+
return [2 /*return*/];
|
|
174
|
+
_a.label = 2;
|
|
175
|
+
case 2:
|
|
176
|
+
_a.trys.push([2, 4, , 5]);
|
|
177
|
+
return [4 /*yield*/, fn()];
|
|
178
|
+
case 3:
|
|
179
|
+
_a.sent();
|
|
180
|
+
this.unlock(key);
|
|
181
|
+
return [3 /*break*/, 5];
|
|
182
|
+
case 4:
|
|
183
|
+
err_3 = _a.sent();
|
|
184
|
+
this.unlock(key);
|
|
185
|
+
throw err_3;
|
|
186
|
+
case 5: return [2 /*return*/];
|
|
187
|
+
}
|
|
188
|
+
});
|
|
189
|
+
});
|
|
190
|
+
};
|
|
164
191
|
return RedisConnection;
|
|
165
192
|
}());
|
|
166
193
|
exports.RedisConnection = RedisConnection;
|