From 11a8aa922e50f9f2d5d64999cf931c76b8418e69 Mon Sep 17 00:00:00 2001 From: Alexander Berl Date: Fri, 28 May 2021 16:57:24 +0200 Subject: [PATCH] feat: add callback option when stale lock is reclaimed Closes #105 --- lib/lockfile.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/lockfile.js b/lib/lockfile.js index 97b6637..ba931c4 100644 --- a/lib/lockfile.js +++ b/lib/lockfile.js @@ -75,7 +75,13 @@ function acquireLock(file, options, callback) { return callback(err); } - acquireLock(file, { ...options, stale: 0 }, callback); + acquireLock(file, { ...options, stale: 0 }, (err) => { + if (!err) { + // Only notify when the lock was actually acquired to make sure only one process can reclaim + options.onReclaimedStale && options.onReclaimedStale(); + } + callback(err); + }); }); }); });