From b60df56157ee1fd0bd4938799bac05a62fda91a1 Mon Sep 17 00:00:00 2001 From: lookshe Date: Sat, 14 Mar 2015 20:45:20 +0100 Subject: initial commit from working version --- signaling-server/node_modules/redis/lib/queue.js | 59 ++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 signaling-server/node_modules/redis/lib/queue.js (limited to 'signaling-server/node_modules/redis/lib/queue.js') diff --git a/signaling-server/node_modules/redis/lib/queue.js b/signaling-server/node_modules/redis/lib/queue.js new file mode 100644 index 0000000..3fc87ab --- /dev/null +++ b/signaling-server/node_modules/redis/lib/queue.js @@ -0,0 +1,59 @@ +// Queue class adapted from Tim Caswell's pattern library +// http://github.com/creationix/pattern/blob/master/lib/pattern/queue.js + +function Queue() { + this.tail = []; + this.head = []; + this.offset = 0; +} + +Queue.prototype.shift = function () { + if (this.offset === this.head.length) { + var tmp = this.head; + tmp.length = 0; + this.head = this.tail; + this.tail = tmp; + this.offset = 0; + if (this.head.length === 0) { + return; + } + } + return this.head[this.offset++]; // sorry, JSLint +}; + +Queue.prototype.push = function (item) { + return this.tail.push(item); +}; + +Queue.prototype.forEach = function (fn, thisv) { + var array = this.head.slice(this.offset), i, il; + + array.push.apply(array, this.tail); + + if (thisv) { + for (i = 0, il = array.length; i < il; i += 1) { + fn.call(thisv, array[i], i, array); + } + } else { + for (i = 0, il = array.length; i < il; i += 1) { + fn(array[i], i, array); + } + } + + return array; +}; + +Queue.prototype.getLength = function () { + return this.head.length - this.offset + this.tail.length; +}; + +Object.defineProperty(Queue.prototype, "length", { + get: function () { + return this.getLength(); + } +}); + + +if (typeof module !== "undefined" && module.exports) { + module.exports = Queue; +} -- cgit v1.2.3