gpt4 book ai didi

javascript - tick 的正确定义是什么?

转载 作者:行者123 更新时间:2023-12-05 04:52:37 31 4
gpt4 key购买 nike

我在 javascript 和 node.js 事件循环中看到了“tick”的不同定义。

  • 有人说这是贯穿所有阶段的第 1 次迭代事件循环。
  • 有人说阶段和阶段之间的过渡另一个是蜱虫。
  • 有人说它是一个事件(或所有事件)来自“事件循环队列”,我知道该 Node 的事件循环每个阶段都有一个队列,而不仅仅是一个队列。 (在除了其他队列“微任务队列”和“下一个滴答”排队”)

所以这让我对“tick”的定义、它到底是什么以及有多少个队列感到困惑。

最佳答案

勾号,根据 NodeJS docsthis paragraph 中有最好的描述

process.nextTick() vs setImmediate()

We have two calls that are similar as far as users are concerned, but their names are confusing.

  • process.nextTick() fires immediately on the same phase
  • setImmediate() fires on the following iteration or 'tick' of the event loop

In essence, the names should be swapped. process.nextTick() fires more immediately than setImmediate(), but this is an artifact of the past which is unlikely to change. Making this switch would break a large percentage of the packages on npm. Every day more new modules are being added, which means every day we wait, more potential breakages occur. While they are confusing, the names themselves won't change.

所以,对我来说,这读作 NodeJS 定义了一个勾号来表示一次通过所有 7 phases事件循环。

不过,老实说,这可能不值得争论。如果您正在与某人进行辩论,您可以向他们展示此文档,但如果他们仍然不服气,请继续,这只是一个词。

关于javascript - tick 的正确定义是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66440155/

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