How would I make it so my requestAddress function is run synchronously? Should I make two functions like this and use callbacks? How would I do the callbacks? I can't seem to understand how to do it for this case.
function requestAddress(urlCombined) {
request(urlCombined, function (error, response, body) {
a = JSON.parse(body);
c = addressInfo.status;
});
}
function isValid() {
// Retrieve address from input
addressGet = $('#address').val();
// Combine url to get address's information
var urlCombined = 'websitehere' + something;
requestAddress(urlCombined);
//do something
if (condition met) {
return true;
} else {
return false;
}
}
if (isValid()) {
do something
}
requestis asynchronous, then no. No matter mow many functions you create, you can never turn asynchronous results into synchronous results. But you changerequestAddressto accept a second argument, a callback function, which you can then call in thefunction (error, response, body) {function.