.$nexttick_了解process.nextTick()

.$nexttick

As you try to understand the Node.js event loop, one important part of it is process.nextTick().

当您尝试了解Node.js事件循环时 ,它的重要部分是process.nextTick()

Every time the event loop takes a full trip, we call it a tick.

每次事件循环进行一次完整的行程时,我们都将其称为对勾。

When we pass a function to process.nextTick(), we instruct the engine to invoke this function at the end of the current operation, before the next event loop tick starts:

当我们将一个函数传递给process.nextTick() ,我们指示引擎在下一个事件循环滴答开始之前,在当前操作结束时调用此函数:

process.nextTick(() => {
  //do something
})

The event loop is busy processing the current function code.

事件循环正在忙于处理当前功能代码。

When this operation ends, the JS engine runs all the functions passed to nextTick calls during that operation.

当该操作结束时,JS引擎将运行该操作期间传递给nextTick调用的所有函数。

It’s the way we can tell the JS engine to process a function asynchronously (after the current function), but as soon as possible, not queue it.

这是我们可以告诉JS引擎异步处理一个函数的方法(在当前函数之后),但是请尽快将其排队。

Calling setTimeout(() => {}, 0) will execute the function at the end of next tick, much later than when using nextTick() which prioritizes the call and executes it just before the beginning of the next tick.

调用setTimeout(() => {}, 0)将在下一个刻度结束时执行该功能,比使用nextTick()优先执行该调用并在下一个刻度开始之前执行时要晚得多。

Use nextTick() when you want to make sure that in the next event loop iteration that code is already executed.

当您要确保在下一个事件循环迭代中已执行代码时,请使用nextTick()

翻译自: https://flaviocopes.com/node-process-nexttick/

.$nexttick

你可能感兴趣的:(python,java,vue,js,javascript,ViewUI)