maiuswong / simaware-express

SimAware on Express.js
Other
24 stars 38 forks source link

Make document ready function async #104

Closed kenkam closed 5 months ago

kenkam commented 5 months ago

Need to bubble async/await to the top level function as well in the handlebar views, otherwise there can also be transient issues in the setInterval if the if block evaluates to true and tries to refresh variables that haven't been initialised yet.

Tested this locally by replacing the statement in the if block to if (true), e.g. in index.handlebars:

    await initialize(); // <-- gotta make sure this is initialised before using it in the setInterval below
    setInterval(
        async () => { 
            if(true) // <-- set this to true to test the await works
            {
                flights = await refreshFlights(filterName, filterCriteria);
                await refreshATC();
                updateInfobar();
                setLayerOrder();
            }
            else
            {
                interpolateLoc();
            }

        }, 1000);

image