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

后端 未结 7 839
抹茶落季
抹茶落季 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:19

    The function c.query() has two argument

    c.query("Fetch Data", "Post-Processing of Data")
    

    The operation "Fetch Data" in this case is a DB-Query, now this may be handled by Node.js by spawning off a worker thread and giving it this task of performing the DB-Query. (Remember Node.js can create thread internally). This enables the function to return instantaneously without any delay

    The second argument "Post-Processing of Data" is a callback function, the node framework registers this callback and is called by the event loop.

    Thus the statement c.query (paramenter1, parameter2) will return instantaneously, enabling node to cater for another request.

    P.S: I have just started to understand node, actually I wanted to write this as comment to @Philip but since didn't have enough reputation points so wrote it as an answer.

提交回复
热议问题