- Learning Node.js Development
- Andrew Mead
- 331字
- 2021-06-30 18:56:42
Blocking and non-blocking software development
Let's go ahead and take a look at the differences between blocking and non blocking software development:

In the preceding screenshot, I have two files that we'll be executing. But before going to that, first let's explore how each of these files operates, the steps that are required in order to finish the program.
This will help us understand the big differences between blocking, which I have on the left side of the image, which is not what Node uses, and non-blocking is on the right side, which is exactly how all of our Node applications in the book are going to operate.
You don't have to understand the individual details, such as what require is, in order to understand what's going on in this code example. We'll be breaking things down in a very general sense. The first line on each code is responsible for fetching a function that gets called. This function will be our simulated I/O function that is going to a database, fetching some user data and printing it to the screen.
Refer to the preceding code image. After we load in the function, both files try to fetch a user with an ID of 123. When it gets that user, it prints it to the screen with the user1 string first, and then it goes on and it fetches the user with 321 as the ID. And it prints that to the screen. And finally both files add up 1 + 2, storing the result, which is 3, in the sum variable and print it to the screen.
Now, while they all do the same thing, they do it in very different ways. Let's break down the individual steps. In the following code image, we'll go over what Node executes and how long it takes:

You can consider the seconds shown in the preceding screenshot; it doesn't really matter, it's just to show the relative operating speed between the two files.
- 微商之道
- Learning Karaf Cellar
- HCNA網(wǎng)絡(luò)技術(shù)
- 網(wǎng)絡(luò)互聯(lián)技術(shù)(實踐篇)
- Socket.IO Real-time Web Application Development
- 數(shù)字調(diào)制解調(diào)技術(shù)的MATLAB與FPGA實現(xiàn):Altera/Verilog版(第2版)
- CCNP TSHOOT(642-832)認證考試指南
- 6G:面向2030年的移動通信
- 網(wǎng)絡(luò)安全應(yīng)急響應(yīng)技術(shù)實戰(zhàn)指南
- 夢工廠之材質(zhì)N次方:Maya材質(zhì)手冊
- 網(wǎng)絡(luò)設(shè)計與應(yīng)用(第2版)
- 從實踐中學(xué)習(xí)手機抓包與數(shù)據(jù)分析
- 大型企業(yè)微服務(wù)架構(gòu)實踐與運營
- 無線傳感器網(wǎng)絡(luò)定位技術(shù)
- 中國互聯(lián)網(wǎng)發(fā)展報告2021