Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

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

In Node.js we a lot talk about the event loop, so I want to know which event loop we are talking about, the Javascript event loop or the libuv event loop ? I guess libuv event loop that provides abstraction for multiple operating system of multiplexing i/o ? Am I right? If not so please explain how this stuff works? I need some internal knowledge, I know what an event loop is, I just want to know how it is connected?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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:

libuv architecture

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...