Permalink
Browse files

Immediate callback if wait time is zero, length getter for LockQueue

  • Loading branch information...
1 parent bf303ab commit bbad2ac4d237ef000c755c413192527f64fe0552 @bobrik committed Jun 14, 2012
Showing with 13 additions and 3 deletions.
  1. +5 −1 lib/Lock.js
  2. +8 −2 lib/LockQueue.js
View
@@ -18,6 +18,11 @@
return true;
}
+ self.queue = self.manager.getQueue(self.getName());
+ if (wait == 0 && self.queue.length) {
+ return callback(new Error("Lock already acquired for " + self.getName()));
+ }
+
self.waitTimer = setTimeout(function() {
if (!self.acquired) {
self.release();
@@ -28,7 +33,6 @@
self.waitTimer = undefined;
}, wait);
- self.queue = self.manager.getQueue(self.getName());
self.queue.push(self, function(error) {
if (self.waitTimer) {
clearTimeout(self.waitTimer);
View
@@ -1,7 +1,13 @@
(function(module) {
function LockQueue(name) {
- this.name = name;
- this.queue = [];
+ var self = this;
+
+ self.name = name;
+ self.queue = [];
+
+ self.__defineGetter__("length", function() {
+ return self.queue.length;
+ });
};
LockQueue.prototype.getName = function() {

0 comments on commit bbad2ac

Please sign in to comment.