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() + })() + }) +})