that are being called and run one after another, into asynchronous functions?
for instance I have two functions named func1 and func2
and they both print their names on the console
I don't want it to always be func1 and then func2
I know I can make them run asynchronous by using setTimeout
just like this :
setTimeout(() => func1(), 0);
setTimeout(() => func2(), 0);
I'd like to know if there are other ways of doing it cleaner and more appropriate
You need to edit the logic inside func1 and func2 to make the logic asynchronous
Well yeah lol
the thing is that these two or more functions are used to inject html code into the DOM, I don't want the whole app to freeze because I call them one after another
Then you need to make them async
Maybe inside func1 you wait a bit everytime you add something to DOM with a setTimeout
How much stuff are you adding to the DOM for it to take that much time
setTimeout fixes the problem all by itself however it makes the code somehow weird and odd
look there is the static part of the app which is gonna be rendered from the server but the rest of app will be loaded from the client using javascript after the DOMContentLoaded event is triggered I'm also thinking of adding an object which has properties which hold true or false depending on the expected parts are loaded or not. and these functions that are meant to load the dynamic parts are going to be called at the very beginning of our DOMContentLoaded handler but the problem shows itself when you realize you can't make them work async by just the way you write the functions, the way they are processed in sync so they stay that way
This questions still stands
Обсуждают сегодня