rwlockfile
Advanced tools
Comparing version 1.4.0 to 1.4.1
@@ -25,3 +25,5 @@ const fs = require('graceful-fs'); | ||
let pid = parseInt(file.trim()); | ||
return pidActive(pid); | ||
let active = pidActive(pid); | ||
if (!active) debug(`stale pid ${path} ${pid}`); | ||
return active; | ||
} catch (err) { | ||
@@ -34,3 +36,2 @@ if (err.code !== 'ENOENT') throw err; | ||
function unlock(path) { | ||
debug(`unlocking ${path}`); | ||
return new Promise(resolve => rimraf(path, resolve)).then(() => { | ||
@@ -46,3 +47,2 @@ delete locks[path]; | ||
function unlockSync(path) { | ||
debug(`unlocking ${path}`); | ||
try { | ||
@@ -57,3 +57,2 @@ rimraf.sync(path); | ||
function lock(p, timeout) { | ||
debug(`locking ${p}`); | ||
let pidPath = path.join(p, 'pid'); | ||
@@ -71,2 +70,3 @@ return new Promise((resolve, reject) => { | ||
if (timeout <= 0) throw new Error(`${p} is locked`); | ||
debug(`locking ${p} ${timeout / 100}s...`); | ||
wait().then(() => lock(p, timeout - 100).then(resolve).catch(reject)); | ||
@@ -197,3 +197,3 @@ }).catch(reject); | ||
let timeout = options.timeout || 60000; | ||
debug(`write(${path}, timeout=${timeout}, skipOwnPid=${skipOwnPid.toString()})`); | ||
debug(`write ${path}`); | ||
await waitForReaders(path, timeout, skipOwnPid); | ||
@@ -213,3 +213,3 @@ await lock(path + '.writer', timeout); | ||
let timeout = options.timeout || 60000; | ||
debug(`read(${path}, timeout=${timeout})`); | ||
debug(`read ${path}`); | ||
await waitForWriter(path, timeout); | ||
@@ -229,2 +229,3 @@ await lock(path + '.readers.lock', timeout); | ||
async function hasWriter(p) { | ||
debug(`hasWriter ${p}`); | ||
let pid; | ||
@@ -247,3 +248,3 @@ try { | ||
let readers = await getActiveReaders(p, timeout, skipOwnPid); | ||
debug(`hasReaders(${p}): ${readers.length}`); | ||
debug(`hasReaders ${p}: ${readers.length}`); | ||
return readers.length !== 0; | ||
@@ -250,0 +251,0 @@ } |
{ | ||
"name": "rwlockfile", | ||
"description": "lockfile utility with reader/writers", | ||
"version": "1.4.0", | ||
"version": "1.4.1", | ||
"author": "Jeff Dickey @dickeyxxx", | ||
"bugs": "https://github.com/dickeyxxx/rwlockfile/issues", | ||
"dependencies": { | ||
"debug": "2.x", | ||
"graceful-fs": "4.x", | ||
@@ -38,3 +39,4 @@ "ps-node": "0.x", | ||
"prepare": "npm run clean && npm run build", | ||
"test": "jest && flow && standard" | ||
"test": "jest && flow && standard", | ||
"watch": "nodemon -e js -i lib --exec \"npm run prepare\"" | ||
}, | ||
@@ -41,0 +43,0 @@ "standard": { |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
10825
225
0
4
+ Addeddebug@2.x
+ Addeddebug@2.6.9(transitive)
+ Addedms@2.0.0(transitive)