lib/pool-base.js
function(pool, iteration, timeoutEnd) {
    return new Promise(function(resolve, reject) {
      const creationTryout = function(resolve, reject) {
        if (closed) {
          reject(
            Errors.createError(
              'Cannot create new connection to pool, pool closed',
              true,
              null,
              '08S01',
              Errors.ER_ADD_CONNECTION_CLOSED_POOL,
              null
            )
          );
          return;
        }
        iteration++;
        createConnectionPool(pool)
          .then(conn => {
            resolve(conn);
          })
          .catch(err => {
            //if timeout is reached or authentication fail return error
            if (
              closed ||
              (err.errno &&
                (err.errno === 1524 ||
                  err.errno === 1045 ||
                  err.errno === 1698)) ||
              timeoutEnd < Date.now()
            ) {
              reject(err);
              return;
            }

            setTimeout(creationTryout.bind(null, resolve, reject), 500);
          });
      };
      //initial without timeout
      creationTryout(resolve, reject);
    });
  }
function(pool, iteration, timeoutEnd) {
    return new Promise(function(resolve, reject) {
      const creationTryout = function(resolve, reject) {
        if (closed) {
          reject(
            Errors.createError(
              'Cannot create new connection to pool, pool closed',
              true,
              null,
              '08S01',
              Errors.ER_ADD_CONNECTION_CLOSED_POOL,
              null
            )
          );
          return;
        }
        iteration++;
        createConnectionPool(pool)
          .then(conn => {
            resolve(conn);
          })
          .catch(err => {
            //if timeout is reached or authentication fail return error
            if (
              closed ||
              (err.errno &&
                (err.errno === 1524 ||
                  err.errno === 1045 ||
                  err.errno === 1698)) ||
              timeoutEnd < Date.now()
            ) {
              reject(err);
              return;
            }

            setTimeout(creationTryout.bind(null, resolve, reject), 500);
          });
      };
      //initial without timeout
      creationTryout(resolve, reject);
    });
  }
function ( pool , iteration , timeoutEnd ) { return new Promise ( function ( resolve , reject ) { const creationTryout = function ( resolve , reject ) { if ( closed ) { reject ( Errors . createError ( 'Cannot create new connection to pool, pool closed' , true , null , '08S01' , Errors . ER_ADD_CONNECTION_CLOSED_POOL , null ) ) ; return ; } iteration ++ ; createConnectionPool ( pool ) . then ( conn => { resolve ( conn ) ; } ) . catch ( err => { //if timeout is reached or authentication fail return error if ( closed || ( err . errno && ( err . errno === 1524 || err . errno === 1045 || err . errno === 1698 ) ) || timeoutEnd < Date . now ( ) ) { reject ( err ) ; return ; } setTimeout ( creationTryout . bind ( null , resolve , reject ) , 500 ) ; } ) ; } ; //initial without timeout creationTryout ( resolve , reject ) ; } ) ; }
Loop for connection creation.
This permits to wait before next try after a connection fail.

@param pool            current pool
@param iteration       current iteration
@param timeoutEnd      ending timeout
@returns {Promise<any>} Connection if found, error if not
Loop for connection creation . This permits to wait before next try after a connection fail .