Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

strict checking in LockQueue, Lock::isWaiting method

  • Loading branch information...
commit 80b44485500b8d9bb2ed5e312000d633d0b8a8fa 1 parent 6482eca
@bobrik authored
Showing with 14 additions and 0 deletions.
  1. +4 −0 lib/Lock.js
  2. +10 −0 lib/LockQueue.js
View
4 lib/Lock.js
@@ -11,6 +11,10 @@
return this.name;
};
+ Lock.prototype.isWaiting = function() {
+ return !!this.waitTimer;
+ }
+
Lock.prototype.acquire = function(wait, timeout, callback) {
var self = this;
View
10 lib/LockQueue.js
@@ -1,4 +1,6 @@
(function(module) {
+ var Lock = require("./Lock");
+
function LockQueue(name) {
var self = this;
@@ -15,6 +17,14 @@
};
LockQueue.prototype.push = function(lock, callback) {
+ if (!(lock instanceof Lock)) {
+ return callback(new Error("Not a lock passed"));
+ }
+
+ if (!lock.isWaiting()) {
+ return callback(new Error("Only waiting locks can be accepted!"));
+ }
+
if (lock.getName() != this.getName()) {
return callback(new Error("Incorrect lock name " + lock.getName() + " for queue " + this.getName()));
}
Please sign in to comment.
Something went wrong with that request. Please try again.