I am trying serialize connection function of mysql drive. But when I did run my function, nodejs make async calls and I can't retrieve the correct value of result. How I can run connection.connect in serialize? I can't use async/await to resolve this problem because the result of a function will turn a promise.
function a(){
var result = "false";
connection = dbConnection.getConnection();
console.log("test1");
connection.connect(function (err) {
console.log("test2");
result = "true";
});
console.log("end of function");
return result;
}
console.log(a());
log:
test1
end of function
false
test2