Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2014
243
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var connect = function(){
  2.       return new q(function(resolve, reject) {
  3.         var sqlCon = mysql.createConnection(connectionObject);
  4.         console.log("connecting");
  5.         sqlCon.connect(function(err) {
  6.           if(err && err.fatal && err.code == "PROTOCOL_CONNECTION_LOST"){
  7.             return reject(false);
  8.           }
  9.           return resolve(true);
  10.  
  11.         });
  12.       });
  13.  
  14.     };
  15.  
  16.     var connectRecursive = function(){
  17.       return connect().then(function(connected){
  18.         if(connected)
  19.         {
  20.           return connected;
  21.         }
  22.         else
  23.         {
  24.           return connectRecursive();
  25.         }
  26.       })
  27.     };
  28.  
  29.     connectRecursive().then(function(res){
  30.       console.log(res);
  31.     });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement