I am currently running a JavaScript function that is quite CPU intensive. To provide visual feedback to users when it starts and stops, I am attempting to display a badge on the webpage. Below is the code snippet:
function updateView() {
console.log(1)
document.getElementById('app-status').className = "badge badge-danger";
document.getElementById('app-status').textContent = "Processing";
console.log(2)
setTimeout(myUpdateView(), 0)
console.log(5)
document.getElementById('app-status').className = "badge badge-success";
document.getElementById('app-status').textContent = "Ready"; console.log(6)
}
function myUpdateView() {
console.log(3)
updateFlightParameters();
// Get departure airport.
var departureAirportICAO = $("#DEPARTURE_AIRPORT").val();
if (airports[departureAirportICAO] === undefined) {
alert("Departure airport is incorrect.");
} else {
departureAirport = airports[departureAirportICAO];
}
// Get arrival airport.
var arrivalAirportICAO = $("#ARRIVAL_AIRPORT").val();
if (airports[arrivalAirportICAO] === undefined) {
alert("Arrival airport is incorrect.");
} else {
arrivalAirport = airports[arrivalAirportICAO];
}
// Create waypoints.
createWaypoint(departureAirport);
createWaypoint(arrivalAirport);
// Create path. THIS FUNCTION CALLS SOME OTHER ASYNC FUNCTIONS.
generatePolylines(flightWaypoints);
console.log(4)
}
The issue I am facing is that the app-status
element does not change its color or text. When the button calling updateView()
is clicked, the page freezes (during the processing) without updating the element.