what is mean by event loop in node.js ? javascript event loop or libuv event loop?

青春壹個敷衍的年華 提交于 2019-11-28 13:08:11

Currently Node uses the the event loop provided by libuv - namely its default event loop: uv_default_loop(). See: An Introduction to libuv by Nikhil Marathe:

A default loop is provided by libuv and can be accessed using uv_default_loop(). You should use this loop if you only want a single loop.

Note: node.js uses the default loop as its main loop. If you are writing bindings you should be aware of this.

There is a linuv architecture diagram on the Design overview page in the libuv API documentation:

In the past, libev's event loop was used in Node. See Understanding the node.js event loop by Mikito Takada:

Internally, node.js relies on libev to provide the event loop, which is supplemented by libeio which uses pooled threads to provide asynchronous I/O. To learn even more, have a look at the libev documentation.

Some good resources on the Node event loop:

Thanks to Saúl Ibarra Corretgé for the clarification in the comments.

There is not just 1 event loop but different implementations of the event loop depending on the context. For example Chrome browser uses the event loop of the V8 JS engine. NodeJS uses the V8 engine but not it's event loop - it uses the Libuv event loop instead.

I made a video with a detailed explanation recently here: https://www.youtube.com/watch?v=4xsvn6VUTwQ

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!