简体   繁体   English

如何计算事件循环(NodeJ)的总滴答声?

[英]How to count total ticks of event loop (NodeJs)?

I'm learning nodejs event loop. 我正在学习nodejs事件循环。 I'm curious if we can count total ticks event loop took throughout the application runtime? 我很好奇我们是否可以计算整个应用程序运行时花费的总滴答声事件循环?

setTimeout(() => {
    console.log("Hey there!")
}, 1000);

As per my understanding, event loop will tick total 2 times before the application ends. 根据我的理解,事件循环将在应用程序结束之前总共滴答2次。 How can I make node tell me exact number of ticks? 如何让节点告诉我准确的滴答数?

The event loop is a system for scheduling tasks and async operations, it uses Queues and Stack under the hood to process function calls. 事件循环是一个用于计划任务和异步操作的系统,它在后台使用队列和堆栈来处理函数调用。 Whenever you get a result of a function, this means the function was put in the Queue and the pushed in to the stack. 每当您获得函数结果时,这都意味着该函数将被放入队列并被推入堆栈。 This way we have non-blocking operation. 这样我们就可以进行非阻塞操作。 What you are trying to do does not make any sense to me, every time you get a log from a function it means this function was processed both by the queue and the stack. 您尝试做的事情对我来说没有任何意义,每次您从函数中获取日志时,这意味着该函数已由队列和堆栈处理。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM