Due to event loop, async code like timeout executes when callstack is empty. But if body of a function takes longer time than a timeout, how to be sure about timeout stuff would run in after spesific duration?
For example, in code below
console.log("start"
setTimeout(()=>{
console.log("do some timeout stuf"))
},1000)
for(let i = 1; i < 10000000000; i++){
//some long-lasting stuff
}
console.log("end")
even if for loop executes in more than 1 second. timeout callback is run after program reaches to end. How to get "do some timeout stuff" input in first second?
I could not find any solution