1
0
mirror of https://github.com/redis/node-redis.git synced 2025-08-06 02:15:48 +03:00

shift in the while loop

This commit is contained in:
Ruben Bridgewater
2015-09-13 00:26:21 +02:00
parent 55d0036eae
commit 30ec1cd6a2
2 changed files with 8 additions and 10 deletions

View File

@@ -17,7 +17,7 @@
"mocha": true, "mocha": true,
// Relaxing options // Relaxing options
"boss": true, // Accept things like `while (command = keys.shift()) { ... }` "boss": true, // Accept statements like `while (key = keys.pop()) {}`
"overrides": { "overrides": {
"examples/*.js": { "examples/*.js": {

View File

@@ -142,16 +142,14 @@ RedisClient.prototype.flush_and_error = function (message) {
error = new Error(message); error = new Error(message);
while (this.offline_queue.length > 0) { while (command_obj = this.offline_queue.shift()) {
command_obj = this.offline_queue.shift();
if (typeof command_obj.callback === "function") { if (typeof command_obj.callback === "function") {
command_obj.callback(error); command_obj.callback(error);
} }
} }
this.offline_queue = new Queue(); this.offline_queue = new Queue();
while (this.command_queue.length > 0) { while (command_obj = this.command_queue.shift()) {
command_obj = this.command_queue.shift();
if (typeof command_obj.callback === "function") { if (typeof command_obj.callback === "function") {
command_obj.callback(error); command_obj.callback(error);
} }
@@ -393,8 +391,8 @@ RedisClient.prototype.ready_check = function () {
RedisClient.prototype.send_offline_queue = function () { RedisClient.prototype.send_offline_queue = function () {
var command_obj, buffered_writes = 0; var command_obj, buffered_writes = 0;
while (this.offline_queue.length > 0) { // TODO: Implement queue.pop() as it should be faster than shift and evaluate petka antonovs queue
command_obj = this.offline_queue.shift(); while (command_obj = this.offline_queue.shift()) {
debug("Sending offline command: " + command_obj.command); debug("Sending offline command: " + command_obj.command);
buffered_writes += !this.send_command(command_obj.command, command_obj.args, command_obj.callback); 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 () { RedisClient.prototype.end = function () {
this.stream._events = {}; this.stream._events = {};
//clear retry_timer // Clear retry_timer
if(this.retry_timer){ if (this.retry_timer){
clearTimeout(this.retry_timer); clearTimeout(this.retry_timer);
this.retry_timer = null; this.retry_timer = null;
} }
this.stream.on("error", function(){}); this.stream.on("error", function noop(){});
this.connected = false; this.connected = false;
this.ready = false; this.ready = false;