Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var connect = function(){
- return new q(function(resolve, reject) {
- var sqlCon = mysql.createConnection(connectionObject);
- sqlCon.connect(function(err) {
- if(err && err.fatal && err.code == "PROTOCOL_CONNECTION_LOST"){
- return reject(err);
- }
- return resolve(sqlCon);
- });
- });
- };
- var connectRecursive = function(){
- var errorCount = 0;
- return connect().catch(function(err) {
- if (errorCount < 3) {
- errorCount++
- } else {
- throw new Error('You failed too many times');
- }
- return connect();
- });
- };
- connectRecursive().then(function(connection) {
- // do something with connection
- }).catch(function(err) {
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement