gpt4 book ai didi

javascript - 作业队列上的 setTimeout 回调是运行还是清除?

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:32:53 24 4
gpt4 key购买 nike

如果 setTimeout 调用的回调被添加到作业队列(例如,如果它在作业队列中是下一个),并且 clearTimeout 被调用事件循环的当前滴答,提供原始 setTimeout 调用的 id。是否会运行作业队列上的 setTimeout 回调?

或者运行时是否神奇地从作业队列中删除了回调?

最佳答案

不,它不会运行;它将排队,然后中止。 The specificiation当您调用 setTimeout 时会经历许多步骤,其中之一(在最短超时之后,加上用户代理填充的超时等)最终是:

  1. Queue the task task.

无论第 10 步中返回的句柄是否已被清除,这似乎都会发生 - 即调用 setTimeout总是导致某些东西被排队.

当你call clearTimeout, it :

must clear the entry identified as handle from the list of active timers

也就是说,它不会直接影响调用 setTimeout 时已经启动的进程。但是请注意,在该过程的更深处,任务 已被定义为:

  1. Let task be a task that runs the following substeps:

    1. If the entry for handle in the list of active timers has been cleared, then abort this task's substeps.

所以当任务开始执行时,它会先检查句柄是否已经被清除。

关于javascript - 作业队列上的 setTimeout 回调是运行还是清除?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32994418/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com