I'm running a webpage in some graphics playout software. The function update() is automatically called by the graphics software when the page initially loads up, however I need to wait for the animation library to finish loading before the code in update() executes.
animation.addEventListener('DOMLoaded', function () { console.log('Animation ready'); }); // This is automatically called by the graphics renderer on page load. function update(data) { // update the data in the animation... }; I've come up with a workaround using setInterval that check if the animation has loaded before running the update code:
var animationLoaded = false; animation.addEventListener('DOMLoaded', function() { console.log('Animation ready'); animationLoaded = true; }); // This is automatically called by the graphics renderer on page load. function update(data) { var updateInterval = setInterval(function() { if (animationLoaded) { clearInterval(updateInterval); // update the data in the animation... } }, 10); } I feel there is a much better way of doing this, maybe using async/await? but I am unsure how to do this?