@jbagatta/johnny-locke
Version:
A robust, strongly-consistent distributed locking library that provides atomic operations across multiple processes
37 lines • 1.2 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.TimeoutError = exports.WritableObject = void 0;
exports.validateLockConfiguration = validateLockConfiguration;
exports.computeLockDuration = computeLockDuration;
class WritableObject {
constructor(value, lockId) {
this.value = value;
this.lockId = lockId;
}
update(value) {
this.value = value;
return this;
}
}
exports.WritableObject = WritableObject;
function validateLockConfiguration(config) {
if (config.defaultLockDurationMs <= 0) {
throw new Error('lockTimeoutMs must be greater than 0');
}
if (config.objectExpiryMs && config.objectExpiryMs <= 0) {
throw new Error('objectExpiryMs must be greater than 0 when set');
}
}
class TimeoutError extends Error {
constructor(key) {
super(`Lock Wait Timeout for key: ${key}`);
this.name = 'TimeoutError';
}
}
exports.TimeoutError = TimeoutError;
function computeLockDuration(defaultTimeout, requestedTimeout) {
if (!requestedTimeout)
return defaultTimeout;
return Math.max(requestedTimeout, defaultTimeout);
}
//# sourceMappingURL=util.js.map