I have following function that promises:
function getAdressValidity(inputed_adress){
var isValid = false;
return new Promise(function(resolve, reject) {
MapApi.geocodeAddress(inputed_adress, function(err, data) {
if(err){
isValid = false;
} else {
isValid = true;
}
resolve(isValid);
});
});
}
And i consume the promise here:
async function isAdressValid(inputed_adress){
var isValid = await getAdressValidity(inputed_adress);
return isValid;
}
Then, as soon as my page is loaded i output the result to console:
console.log(Order.isAdressValid("1231231232"));
Which gives this output:
If i place console.log like that, it ouputes awaited result:
async function isAdressValid(inputed_adress){
var isValid = await getAdressValidity(inputed_adress);
console.log(isValid);
// return isValid;
}
Is there a way to wait for the result in other thread, while returning the value in the synchronous matter, like my function is expected to do?