Comparing version 1.0.1 to 1.1.0
16
index.js
var mutexify = function() { | ||
var queue = [] | ||
var used = false | ||
var used = null | ||
var acquire = function(fn) { | ||
var call = function () { | ||
used(release) | ||
} | ||
var acquire = function (fn) { | ||
if (used) return queue.push(fn) | ||
used = true | ||
fn(release) | ||
used = fn | ||
process.nextTick(call) | ||
return 0 | ||
} | ||
var release = function(fn, err, value) { | ||
used = false | ||
var release = function (fn, err, value) { | ||
used = null | ||
if (queue.length) acquire(queue.shift()) | ||
@@ -15,0 +19,0 @@ if (fn) fn(err, value) |
{ | ||
"name": "mutexify", | ||
"version": "1.0.1", | ||
"version": "1.1.0", | ||
"description": "mutex lock for javascript", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
25
test.js
@@ -34,2 +34,25 @@ var tape = require('tape') | ||
}) | ||
}) | ||
}) | ||
tape('calls the locking callbacks in a different stack', function(t) { | ||
t.plan(2) | ||
var lock = mutexify() | ||
var topScopeFinished = false | ||
var secondScopeFinished = false | ||
lock(function(release) { | ||
t.ok(topScopeFinished, 'the test function has already finished running') | ||
release() | ||
secondScopeFinished = true | ||
}) | ||
lock(function(release) { | ||
t.ok(secondScopeFinished, 'the last lock\'s call stack is done') | ||
release() | ||
t.end() | ||
}) | ||
topScopeFinished = true | ||
}) |
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
4098
64