@@ -394,9 +394,25 @@ RedisClient.prototype.send_offline_queue = function () {
394394 }
395395} ;
396396
397- RedisClient . prototype . connection_gone = function ( why ) {
398- var self = this ;
397+ var retry_connection = function ( self ) {
398+ debug ( "Retrying connection..." ) ;
399+
400+ self . emit ( "reconnecting" , {
401+ delay : self . retry_delay ,
402+ attempt : self . attempts
403+ } ) ;
404+
405+ self . retry_totaltime += self . retry_delay ;
406+ self . attempts += 1 ;
407+ self . retry_delay = Math . round ( self . retry_delay * self . retry_backoff ) ;
408+
409+ self . stream = net . createConnection ( self . connectionOption ) ;
410+ self . install_stream_listeners ( ) ;
411+
412+ self . retry_timer = null ;
413+ } ;
399414
415+ RedisClient . prototype . connection_gone = function ( why ) {
400416 // If a retry is already in progress, just let that happen
401417 if ( this . retry_timer ) {
402418 return ;
@@ -452,23 +468,7 @@ RedisClient.prototype.connection_gone = function (why) {
452468
453469 debug ( "Retry connection in " + this . retry_delay + " ms" ) ;
454470
455- this . retry_timer = setTimeout ( function ( ) {
456- debug ( "Retrying connection..." ) ;
457-
458- self . emit ( "reconnecting" , {
459- delay : self . retry_delay ,
460- attempt : self . attempts
461- } ) ;
462-
463- self . retry_totaltime += self . retry_delay ;
464- self . attempts += 1 ;
465- self . retry_delay = Math . round ( self . retry_delay * self . retry_backoff ) ;
466-
467- self . stream = net . createConnection ( self . connectionOption ) ;
468- self . install_stream_listeners ( ) ;
469-
470- self . retry_timer = null ;
471- } , this . retry_delay ) ;
471+ this . retry_timer = setTimeout ( retry_connection , this . retry_delay , this ) ;
472472} ;
473473
474474RedisClient . prototype . on_data = function ( data ) {
0 commit comments