当你第一次运行你的 Node 程序时,第一个事件是如何/什么提供给事件循环的?你的程序是否像一个一直在执行的顶级回调? (我假设这个顶级回调通常是“server.listen()”?)
最佳答案
I'm confused about whether the event loop exists outside of the "main" script (or entry point) being ran, or if the event loop runs the "main" script itself
实际上,两者都是。事件循环是包装所有js代码执行的机制,只要有事件等待就不会停止。
what is the first event supplied to the event loop?
这是对主脚本的评价。 (或者更确切地说,最终将评估主脚本的 native Node.js 代码是首先放在 V8 事件循环中的代码)。
Is your program like a top-level callback that is being executed the entire time?
不,自始至终什么都不执行,每个回调都是单独执行的。
关于javascript - Node.js 如何将代码转换为事件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44352385/