From 30ec1cd6a2095fc09893e2eaf154d83e8274abee Mon Sep 17 00:00:00 2001 From: Ruben Bridgewater Date: Sun, 13 Sep 2015 00:26:21 +0200 Subject: [PATCH] shift in the while loop --- .jshintrc | 2 +- index.js | 16 +++++++--------- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/.jshintrc b/.jshintrc index c5caf777dd..92441eb976 100644 --- a/.jshintrc +++ b/.jshintrc @@ -17,7 +17,7 @@ "mocha": true, // Relaxing options - "boss": true, // Accept things like `while (command = keys.shift()) { ... }` + "boss": true, // Accept statements like `while (key = keys.pop()) {}` "overrides": { "examples/*.js": { diff --git a/index.js b/index.js index 25ebb5c015..113c2141b2 100644 --- a/index.js +++ b/index.js @@ -142,16 +142,14 @@ RedisClient.prototype.flush_and_error = function (message) { error = new Error(message); - while (this.offline_queue.length > 0) { - command_obj = this.offline_queue.shift(); + while (command_obj = this.offline_queue.shift()) { if (typeof command_obj.callback === "function") { command_obj.callback(error); } } this.offline_queue = new Queue(); - while (this.command_queue.length > 0) { - command_obj = this.command_queue.shift(); + while (command_obj = this.command_queue.shift()) { if (typeof command_obj.callback === "function") { command_obj.callback(error); } @@ -393,8 +391,8 @@ RedisClient.prototype.ready_check = function () { RedisClient.prototype.send_offline_queue = function () { var command_obj, buffered_writes = 0; - while (this.offline_queue.length > 0) { - command_obj = this.offline_queue.shift(); + // TODO: Implement queue.pop() as it should be faster than shift and evaluate petka antonovs queue + while (command_obj = this.offline_queue.shift()) { debug("Sending offline command: " + command_obj.command); buffered_writes += !this.send_command(command_obj.command, command_obj.args, command_obj.callback); } @@ -826,12 +824,12 @@ RedisClient.prototype.pub_sub_command = function (command_obj) { RedisClient.prototype.end = function () { this.stream._events = {}; - //clear retry_timer - if(this.retry_timer){ + // Clear retry_timer + if (this.retry_timer){ clearTimeout(this.retry_timer); this.retry_timer = null; } - this.stream.on("error", function(){}); + this.stream.on("error", function noop(){}); this.connected = false; this.ready = false;