Can anyone please help with the following?
In my main html page I use the onLoad method of the DOM like so:
<body onLoad="OnLoad()">
My OnLoad method is:
function OnLoad()
{
var thing = new Thing();
thing.GetAsync();
alert("T");
}
Where Thing is:
function Thing()
{
}
Thing.prototype.GetAsync = async function ()
{
var result = await this.AsyncFunc();
alert(result);
}
Thing.prototype.AsyncFunc = async function ()
{
return new Promise(resolve => {
setTimeout(() => {
resolve("Text");
}, 2000);
});
}
When I run this I see "T" immediately and 2 seonds later I see "Text".
Is it possible to await the result of thing.GetAsync() so that "T" will always come after "Text" in the OnLoad method? I gather this may not be possible as it would be attmepting to pause the main browser thread?