index.js
function _try() {
            // Call function

            Q.invoke(f)
            .then(function(result) {
                // Success
                d.resolve(result);
            }, function(err) {
                // Failure

                // Decrement
                remainingTries -= 1;

                // No tries left, so reject promise with last error
                if(remainingTries >= 0 && canContinue(err, N - remainingTries)) {
                    // We have some retries left, so retryTimeout
                    if(retryTimeout) {
                        setTimeout(_try, retryTimeout);
                    } else {
                        _try();
                    }
                } else {
                    // Total failure
                    d.reject(err);
                    return;
                }
            }).done();
        }
function _try() {
            // Call function

            Q.invoke(f)
            .then(function(result) {
                // Success
                d.resolve(result);
            }, function(err) {
                // Failure

                // Decrement
                remainingTries -= 1;

                // No tries left, so reject promise with last error
                if(remainingTries >= 0 && canContinue(err, N - remainingTries)) {
                    // We have some retries left, so retryTimeout
                    if(retryTimeout) {
                        setTimeout(_try, retryTimeout);
                    } else {
                        _try();
                    }
                } else {
                    // Total failure
                    d.reject(err);
                    return;
                }
            }).done();
        }
function _try ( ) { // Call function Q . invoke ( f ) . then ( function ( result ) { // Success d . resolve ( result ) ; } , function ( err ) { // Failure // Decrement remainingTries -= 1 ; // No tries left, so reject promise with last error if ( remainingTries >= 0 && canContinue ( err , N - remainingTries ) ) { // We have some retries left, so retryTimeout if ( retryTimeout ) { setTimeout ( _try , retryTimeout ) ; } else { _try ( ) ; } } else { // Total failure d . reject ( err ) ; return ; } } ) . done ( ) ; }
The function with the try logic
The function with the try logic