@sesamecare-oss/redlock
Advanced tools
Comparing version 1.3.1 to 1.4.0
@@ -50,3 +50,4 @@ /// <reference types="node" /> | ||
expiration: number; | ||
constructor(redlock: Redlock, resources: string[], value: string, attempts: ReadonlyArray<Promise<ExecutionStats>>, expiration: number); | ||
readonly settings?: Partial<Settings> | undefined; | ||
constructor(redlock: Redlock, resources: string[], value: string, attempts: ReadonlyArray<Promise<ExecutionStats>>, expiration: number, settings?: Partial<Settings> | undefined); | ||
release(): Promise<ExecutionResult>; | ||
@@ -53,0 +54,0 @@ extend(duration: number): Promise<Lock>; |
@@ -56,3 +56,4 @@ "use strict"; | ||
expiration; | ||
constructor(redlock, resources, value, attempts, expiration) { | ||
settings; | ||
constructor(redlock, resources, value, attempts, expiration, settings) { | ||
this.redlock = redlock; | ||
@@ -63,2 +64,3 @@ this.resources = resources; | ||
this.expiration = expiration; | ||
this.settings = settings; | ||
} | ||
@@ -69,3 +71,3 @@ async release() { | ||
async extend(duration) { | ||
return this.redlock.extend(this, duration); | ||
return this.redlock.extend(this, duration, this.settings); | ||
} | ||
@@ -157,3 +159,3 @@ } | ||
const drift = Math.round((settings?.driftFactor ?? this.settings.driftFactor) * duration) + 2; | ||
return new Lock(this, resources, value, attempts, start + duration - drift); | ||
return new Lock(this, resources, value, attempts, start + duration - drift, settings); | ||
} | ||
@@ -201,3 +203,3 @@ catch (error) { | ||
const drift = Math.round((settings?.driftFactor ?? this.settings.driftFactor) * duration) + 2; | ||
return new Lock(this, existing.resources, existing.value, attempts, start + duration - drift); | ||
return new Lock(this, existing.resources, existing.value, attempts, start + duration - drift, settings); | ||
} | ||
@@ -204,0 +206,0 @@ /** |
{ | ||
"name": "@sesamecare-oss/redlock", | ||
"version": "1.3.1", | ||
"version": "1.4.0", | ||
"description": "A modern node.js redlock implementation for distributed redis locks", | ||
@@ -5,0 +5,0 @@ "main": "build/index.js", |
@@ -105,2 +105,3 @@ import { randomBytes, createHash } from 'crypto'; | ||
public expiration: number, | ||
public readonly settings?: Partial<Settings>, | ||
) {} | ||
@@ -113,3 +114,3 @@ | ||
async extend(duration: number): Promise<Lock> { | ||
return this.redlock.extend(this, duration); | ||
return this.redlock.extend(this, duration, this.settings); | ||
} | ||
@@ -236,3 +237,3 @@ } | ||
return new Lock(this, resources, value, attempts, start + duration - drift); | ||
return new Lock(this, resources, value, attempts, start + duration - drift, settings); | ||
} catch (error) { | ||
@@ -297,3 +298,3 @@ // If there was an error acquiring the lock, release any partial lock | ||
return new Lock(this, existing.resources, existing.value, attempts, start + duration - drift); | ||
return new Lock(this, existing.resources, existing.value, attempts, start + duration - drift, settings); | ||
} | ||
@@ -300,0 +301,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
117280
1317