Presently, I am executing the following code but it is causing the call stack to slow down; how can I optimize this using either an async
await
or more advanced promise functions? I have a dynamic node that is added to the DOM at different times depending on various load times - instead of continuously checking like in the example below, is there a way to handle this more efficiently with async
await
somehow?
function checkForNode() {
let coolNode= document.getElementById("CoolDomNode");
if (coolNode) {
doManyThings(coolNode);
} else {
checkForNode()
}
}