How the single threaded non blocking IO model works in Node.js

后端 未结 7 973
抹茶落季
抹茶落季 2020-11-22 05:29

I\'m not a Node programmer, but I\'m interested in how the single threaded non blocking IO model works. After I read the article understanding-the-node-js-e

7条回答
  •  野趣味
    野趣味 (楼主)
    2020-11-22 06:09

    Node.js uses libuv behind the scenes. libuv has a thread pool (of size 4 by default). Therefore Node.js does use threads to achieve concurrency.

    However, your code runs on a single thread (i.e., all of the callbacks of Node.js functions will be called on the same thread, the so called loop-thread or event-loop). When people say "Node.js runs on a single thread" they are really saying "the callbacks of Node.js run on a single thread".

提交回复
热议问题