Promises don't change the language, it's just a library. It cannot change how function returning works. However, do you want something like this:
return con.getConnectionAsync().then(function(connection) {
var x;
var y;
return connection.queryAsync('SELECT password,id FROM player WHERE name='+mysql.escape(req.body.user))
.spread(function(rows, fields) {
if (hash.verify(req.body.pass,rows[0].password)) {
req.session.loggedIn = true;
req.session.user = rows[0].id;
ref = new P(rows[0].id,x,y);
res.send({
"msg":"You have logged in!",
"flag":false,
"title":": Logged In"
});
return Promise.all([
getX(rows[0].id,con,mysql),
getY(rows[0].id,con,mysql)
]).then(function(xy) {
x = xy[0];
y = xy[1];
}).return(ref);
} else {
// Should probably throw a LoginError here or something
// because if we get here, we don't define x and y
// and that will require an annoying check later
res.send({
"msg":"Your username and or password was incorrect.",
"flag":true,
"title":": Login Failed"
});
}
}).then(function() {
// If the login succeeded x and y are defined here.
// However, in the else branch you don't define
// x and y so you will need to check here.
// Had you thrown an error in the else branch
// you would know that x and y are always defined here.
use(x, y);
}).finally(function() {
connection.release();
});
});