一段时间后终止被调用的函数

时间:2022-05-13 04:48:15

provided the following code:

提供了以下代码:

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

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

更新是否有可能在给定时间后停止等待函数调用的返回而不更改someFun?

1 个解决方案

#1


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

更新是否有可能在给定时间后停止等待函数调用的返回而不更改someFun?

No.

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

没有什么可以干预当前的执行上下文。从MDN文档:

"Run-to-completion"

Each message is processed completely before any other message is processed. This offers some nice properties when reasoning about your program, including the fact that whenever a function runs, it cannot be pre-empted and will run entirely before any other code runs (and can modify data the function manipulates). This differs from C, for instance, where if a function runs in a thread, it can be stopped at any point to run some other code in another thread.

在处理任何其他消息之前,将完全处理每条消息。这在推理程序时提供了一些不错的属性,包括每当函数运行时,它都不能被抢占并且在任何其他代码运行之前完全运行(并且可以修改函数操作的数据)。这与C不同,例如,如果一个函数在一个线程中运行,它可以在任何时候停止在另一个线程中运行一些其他代码。

#1


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

更新是否有可能在给定时间后停止等待函数调用的返回而不更改someFun?

No.

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

没有什么可以干预当前的执行上下文。从MDN文档:

"Run-to-completion"

Each message is processed completely before any other message is processed. This offers some nice properties when reasoning about your program, including the fact that whenever a function runs, it cannot be pre-empted and will run entirely before any other code runs (and can modify data the function manipulates). This differs from C, for instance, where if a function runs in a thread, it can be stopped at any point to run some other code in another thread.

在处理任何其他消息之前,将完全处理每条消息。这在推理程序时提供了一些不错的属性,包括每当函数运行时,它都不能被抢占并且在任何其他代码运行之前完全运行(并且可以修改函数操作的数据)。这与C不同,例如,如果一个函数在一个线程中运行,它可以在任何时候停止在另一个线程中运行一些其他代码。