I need to implement a validation process where the app checks the database for a specific value every 2 seconds until it is found.
let confirmation = false;
do {
await this.sleep(2 * 1000);
confirmation = this.validateSession(hash);
console.log(confirmation);
} while (!confirmation);
validateSession(hash) {
let sqlQuery = "SELECT user_id FROM session WHERE hash='" + hash + "';";
this.db.execute(sqlQuery).then(response => {
if (response[0].user_id !== null) {
console.log("Expected to return true");
return true;
}
}).catch(error => {
return false;
});
return false;
}
The issue I am facing is that the function always returns false
, even though the message
console.log("Expected to return true");
shows up. I suspect it's because I am calling a non-async function inside an async function. Any suggestions?