- Node.js Design Patterns(Second Edition)
- Mario Casciaro Luciano Mammino
- 267字
- 2021-07-14 11:01:24
Chapter 2. Node.js Essential Patterns
Embracing the asynchronous nature of Node.js is not trivial at all, especially if coming from a language such as PHP where it is not usual to deal with asynchronous code.
In synchronous programming, we are used to the concept of imagining code as a series of consecutive computing steps defined to solve a specific problem. Every operation is blocking, which means that only when an operation is completed is it possible to execute the next one. This approach makes the code easy to understand and debug.
Instead, in asynchronous programming, some operations, such as reading a file or performing a network request, can be executed as an operation in the background. When an asynchronous operation is invoked, the next one is executed immediately, even if the previous operation has not finished yet. The operations pending in the background can complete at any time, and the whole application should be programmed to react in the proper way when an asynchronous call finishes.
While this non-blocking approach could almost always guarantee superior performance compared to an always-blocking scenario, it provides a paradigm that could be hard to reason about and that can get really cumbersome when dealing with more advanced applications that require complex control flows.
Node.js offers a series of tools and design patterns to deal optimally with asynchronous code. It's important to learn how to use them to gain confidence and write applications that are both performant and easy to understand and debug.
In this chapter, we will see two of the most important asynchronous patterns: callback and event emitter.
- 從零構建知識圖譜:技術、方法與案例
- Learning C# by Developing Games with Unity 2020
- Java EE 6 企業級應用開發教程
- Apache Hive Essentials
- Java技術手冊(原書第7版)
- FFmpeg入門詳解:音視頻流媒體播放器原理及應用
- Koa開發:入門、進階與實戰
- Java性能權威指南(第2版)
- 零基礎Java學習筆記
- Visual C#.NET Web應用程序設計
- 從零開始學Python大數據與量化交易
- 計算機系統解密:從理解計算機到編寫高效代碼
- 你好!Python
- Learning QGIS(Second Edition)
- C/C++語言程序開發參考手冊