Permalink
Browse files

clearing timeouts, typo and but fixes, removed sequence check

  • Loading branch information...
1 parent 0678385 commit 6c85ed7e138669752b6a2905c61bedc5178ed397 @bobrik committed Jun 10, 2012
Showing with 23 additions and 22 deletions.
  1. +12 −18 index.js
  2. +11 −4 lib/Lock.js
View
@@ -48,28 +48,22 @@
data = new Buffer(temp);
while (data.length && ((data[0] + 14) <= data.length)) {
+ length = data[0];
sequence = data.readUInt32LE(1);
+ wait = data.readUInt32LE(5);
+ timeout = data.readUInt32LE(9);
action = data[13];
+ name = data.slice(14, length + 14).toString();
- if (currentSequence < sequence && action != LockAction.ACTION_UNLOCK) {
- currentSequence = sequence;
+ currentSequence = sequence;
- length = data[0];
- wait = data.readUInt32LE(5);
- timeout = data.readUInt32LE(9);
- name = data.slice(14, length + 14).toString();
-
- if (action == LockAction.ACTION_LOCK) {
- lock(name, sequence, wait, timeout);
- } else if (action == LockAction.ACTION_UNLOCK) {
- unlock(sequence);
- }
-
- data = data.slice(length + 14);
- } else {
- connection.end();
- break;
+ if (action == LockAction.ACTION_LOCK) {
+ lock(name, sequence, wait, timeout);
+ } else if (action == LockAction.ACTION_UNLOCK) {
+ unlock(sequence);
}
+
+ data = data.slice(length + 14);
}
});
@@ -108,7 +102,7 @@
Locker.prototype.listen = function() {
this.server.listen.apply(this.server, arguments);
};
-=
+
Locker.prototype.close = function() {
this.server.close.apply(this.server, arguments);
};
View
@@ -23,13 +23,19 @@
self.release();
callback(new Error("Lock waiting timeout for " + self.getName()));
}
+
+ clearTimeout(self.waitTimer);
+ self.waitTimer = undefined;
}, wait);
self.queue = self.manager.getQueue(self.getName());
self.queue.push(self, function(error) {
if (self.waitTimer) {
clearTimeout(self.waitTimer);
self.waitTimer = undefined;
+ } else {
+ // already returned
+ return;
}
if (error) {
@@ -44,16 +50,17 @@
if (self.acquired) {
self.release();
}
+
+ clearTimeout(self.timeoutTimer);
+ self.timeoutTimer = undefined;
}, timeout);
});
return false;
};
Lock.prototype.release = function() {
- if (!this.acquired) {
- return false;
- }
+ var result = this.acquired;
if (this.waitTimer) {
clearTimeout(this.waitTimer);
@@ -68,7 +75,7 @@
this.queue.pop(this);
this.acquired = false;
- return true;
+ return result;
};
module.exports = Lock;

0 comments on commit 6c85ed7

Please sign in to comment.