Terminate the called function after a while

provided the following code:

function update() {
var ret = someFun();
}
function someFun() {
while(true) { var i = 0 }
}

      

Is it possible that the update stops waiting for the function call to return after a given time without changing someFun?

+3


source to share


1 answer


Is it possible that the update stops waiting for the function call to return after a given time without changing someFun?

Not



Nothing can interfere with the current execution context. From MDN documentation :

"Run to completion"

Each message is processed completely before any other message is processed. This gives some nice properties when you reason about your program, including the fact that whenever any function is run, it cannot be pre-missed and will run completely before any other code runs (and may change data that the function manipulates). This is different from C, for example, if a function is running on a thread, it can be stopped at any point to run other code on a different thread.

+6


source







All Articles