Promises work beautifully for updates.
Your functions are not the same:
con.getConnection(function(err,connection){
if (err) console.log("Get Connection Error.. "+err);
con.query("UPDATE player_data SET x="+mysql.escape(x)+", y="+mysql.escape(y)+" WHERE id="+mysql.escape(this.id),function(err) {
if (err) console.log(err);
// continue even if error!
connection.release();
});
req.io.emit("talk", {x:req.data.x,y:req.data.y}); // <- Emit before query
console.log(this.x,this.y);
});
I'll note again, you continue the handling even if there was an error, and emit "talk"
without waiting for the query. That is, your callback version was incorrect to begin with.