I'm making a dialog box in a HTML layer in Javascript. When I call it, I want it to behave just like when I call the built-in Alert box. It should yield the GUI thread when called, and then resume execution on the next code line when it is closed down. From the caller's perspective, it acts as if it blocks the GUI thread. Is this possible in Javascript?
In the main function below, I want the execution state of the function to be preserved right when showDialog is called. The dialog is then shown, and receives click events, etc, and when it finally closes down, I want the return value to be passed back to the result variable and execution resumes in the main function. Is this possible somehow? I am not taking about actually blocking the GUI thread, because then the dialog would not work.
function main()
{
// Show the dialog to warn
let result = showDialog("Warning", "Do you want to continue?", ["OK", "Cancel"]);
// Do some stuff.
if (result === "OK") performAction();
}
// This function shows a custom modal dialog (HTML layer), and should only return the GUI
// thread when the user has clicked one of the buttons.
function showDialog(title, text, buttons)
{
// Code here to draw the dialog and catch button events.
}