From b4e2b7f5f8d4f6244c77b76bfde416f1cc6842ea Mon Sep 17 00:00:00 2001
From: Harrison Massey
Date: Wed, 12 Nov 2014 15:22:55 -0600
Subject: [PATCH] done is optional with multiple locks
---
index.js | 2 +-
test/multi.js | 16 ++++++++++++++++
2 files changed, 17 insertions(+), 1 deletion(-)
diff --git a/index.js b/index.js
index 63ecb4a5..c3735f07 100644
--- a/index.js
+++ b/index.js
@@ -44,7 +44,7 @@ module.exports = function () {
var args = [].slice.call(arguments)
for(var key in l)
_release(key, l[key])
- done.apply(this, args)
+ if (done) done.apply(this, args)
}
}
diff --git a/test/multi.js b/test/multi.js
index e11057a6..cdaeceb6 100644
--- a/test/multi.js
+++ b/test/multi.js
@@ -58,3 +58,19 @@ tape('wait for a single lock', function (t) {
})()
})
})
+
+tape('multiple locks with optional done', function (t) {
+ var lock = Lock(), released = 0
+
+ lock(['a', 'b'], function (release) {
+ released = 1
+ process.nextTick(release())
+ })
+
+ lock(['a', 'b'], function (release) {
+ t.equal(released, 1, 'first lock should be completely released')
+ release(function () {
+ t.end()
+ })()
+ })
+})