rwlockfile
Advanced tools
Comparing version 2.0.21 to 2.0.22
import { Status } from './rwlockfile'; | ||
export declare class LockfileError extends Error { | ||
code: string; | ||
msg: string; | ||
file: string; | ||
reason: string; | ||
msg: string | undefined; | ||
reason: string | undefined; | ||
constructor({msg, file, reason}: { | ||
@@ -8,0 +8,0 @@ file: string; |
@@ -7,2 +7,5 @@ "use strict"; | ||
this.code = 'ELOCK'; | ||
this.file = file; | ||
this.msg = msg; | ||
this.reason = reason; | ||
} | ||
@@ -9,0 +12,0 @@ } |
@@ -23,3 +23,3 @@ export interface LockfileOptions { | ||
private _count; | ||
private updater; | ||
private updater?; | ||
/** | ||
@@ -26,0 +26,0 @@ * creates a new simple lockfile without read/write support |
@@ -306,3 +306,4 @@ "use strict"; | ||
_stopLocking() { | ||
clearInterval(this.updater); | ||
if (this.updater) | ||
clearInterval(this.updater); | ||
this._count = 0; | ||
@@ -309,0 +310,0 @@ } |
@@ -79,3 +79,3 @@ import { LockfileOptions } from './lockfile'; | ||
private _lock(type, opts); | ||
tryLock(type: RWLockType, reason?: string): Promise<void>; | ||
tryLock(type: RWLockType, reason?: string, inc?: boolean): Promise<void>; | ||
private _lockSync(type, reason?); | ||
@@ -82,0 +82,0 @@ private writeFile(f); |
@@ -37,3 +37,3 @@ "use strict"; | ||
this._debugReport('add', type, opts); | ||
if (!this.count[type]) | ||
if (!this._count[type]) | ||
await this._lock(type, opts); | ||
@@ -44,5 +44,3 @@ this._count[type]++; | ||
this._debugReport('addSync', type, opts); | ||
if (!this.count[type]) | ||
this._lockSync(type, opts.reason); | ||
this._count[type]++; | ||
this._lockSync(type, opts.reason); | ||
} | ||
@@ -251,3 +249,3 @@ async remove(type) { | ||
try { | ||
await this.tryLock(type, opts.reason); | ||
await this.tryLock(type, opts.reason, false); | ||
return; | ||
@@ -269,3 +267,9 @@ } | ||
} | ||
async tryLock(type, reason) { | ||
async tryLock(type, reason, inc = false) { | ||
if (this.count[type]) { | ||
if (inc) | ||
this._count[type]++; | ||
return; | ||
} | ||
this.debug('tryLock', type, reason); | ||
const status = await this.check(type); | ||
@@ -279,4 +283,11 @@ if (status.status !== 'open') { | ||
await this.writeFile(f); | ||
if (inc) | ||
this._count[type]++; | ||
this.debug('got %s lock for %s', type, reason); | ||
} | ||
_lockSync(type, reason) { | ||
if (this._count[type]) { | ||
this._count[type]++; | ||
return; | ||
} | ||
const status = this.checkSync(type); | ||
@@ -290,2 +301,4 @@ if (status.status !== 'open') { | ||
this.writeFileSync(f); | ||
this._count[type]++; | ||
this.debug('got %s lock for %s', type, reason); | ||
} | ||
@@ -339,3 +352,3 @@ async writeFile(f) { | ||
tslib_1.__decorate([ | ||
decorators_1.onceAtATime(1) | ||
decorators_1.onceAtATime(0) | ||
], RWLockfile.prototype, "_lock", null); | ||
@@ -342,0 +355,0 @@ tslib_1.__decorate([ |
{ | ||
"name": "rwlockfile", | ||
"description": "lockfile utility with reader/writers", | ||
"version": "2.0.21", | ||
"version": "2.0.22", | ||
"author": "Jeff Dickey @jdxcode", | ||
@@ -16,5 +16,5 @@ "bugs": "https://github.com/jdxcode/rwlockfile/issues", | ||
"@types/fs-extra": "^5.0.0", | ||
"@types/jest": "^22.0.1", | ||
"@types/lodash": "^4.14.92", | ||
"@types/node": "^9.3.0", | ||
"@types/jest": "^22.1.1", | ||
"@types/lodash": "^4.14.99", | ||
"@types/node": "^9.4.0", | ||
"@types/uuid": "^3.4.3", | ||
@@ -26,7 +26,7 @@ "debug": "^3.1.0", | ||
"prettier": "^1.10.2", | ||
"ts-jest": "^22.0.1", | ||
"typescript": "^2.6.2" | ||
"ts-jest": "^22.0.2", | ||
"typescript": "^2.7.1" | ||
}, | ||
"engines": { | ||
"node": ">=6.0.0" | ||
"node": ">=8.0.0" | ||
}, | ||
@@ -33,0 +33,0 @@ "files": [ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
35385
1098