function () { // failed this attempt, possibly try again
                    if (attemptCount < CONNECTION_ATTEMPTS) { //try again
                        // Calculate how long we should wait before trying again
                        var now = new Date();
                        var delay = Math.max(
                            RETRY_DELAY - (now - attemptTimestamp),
                            1
                        );
                        setTimeout(doConnect, delay);
                    } else { // too many attempts, give up
                        deferred.reject("Max connection attempts reached");
                    }
                }
function () { // failed this attempt, possibly try again
                    if (attemptCount < CONNECTION_ATTEMPTS) { //try again
                        // Calculate how long we should wait before trying again
                        var now = new Date();
                        var delay = Math.max(
                            RETRY_DELAY - (now - attemptTimestamp),
                            1
                        );
                        setTimeout(doConnect, delay);
                    } else { // too many attempts, give up
                        deferred.reject("Max connection attempts reached");
                    }
                }
function ( ) { // failed this attempt, possibly try again if ( attemptCount < CONNECTION_ATTEMPTS ) { //try again // Calculate how long we should wait before trying again var now = new Date ( ) ; var delay = Math . max ( RETRY_DELAY - ( now - attemptTimestamp ) , 1 ) ; setTimeout ( doConnect , delay ) ; } else { // too many attempts, give up deferred . reject ( "Max connection attempts reached" ) ; } }
succeded
succeded
If we have too many attempts to connect then give up