官术网_书友最值得收藏!

Listening for events

Modern network software, for various reasons, is growing in complexity and, in many ways, changing how we think about application development. Most new platforms and languages are attempting to address these changes. Node is no exception — and JavaScript is no exception.

Learning about Node means learning about event-driven programming, composing software out of modules, creating and linking data streams, and producing and consuming events and their related data. Node-based architectures are often composed of many small processes and/or services communicating with events — internally, by extending the EventEmitter interface and using callbacks, and externally, over one of several common transport layers (for example, HTTP, TCP), or through a thin messaging layer covering one of these transport layers (for example, 0MQ, Redis PUBSUB, and Kafka).

It is likely that these processes are composed of several free, open source, and high-quality npm modules, each distributed with unit tests and/or examples and/or documentation.

The previous chapter introduced you to the EventEmitter interface. This is the primary event interface we will be encountering as we move chapter to chapter, as it provides the prototype class for the many Node objects exposing evented interfaces, such as file and network streams. Various close, exit, data, and other events exposed by different module APIs signal the presence of an EventEmitter interface, and we will be learning about these modules and use cases as we progress.

In this section, our goal is to discuss some lesser-known event sources: signals, child process communication, filesystem change events, and deferred execution.

主站蜘蛛池模板: 油尖旺区| 年辖:市辖区| 美姑县| 宿迁市| 阳曲县| 红桥区| 乌鲁木齐市| 博乐市| 平南县| 铁力市| 东乡族自治县| 砚山县| 木兰县| 广元市| 岳普湖县| 凤翔县| 丹东市| 罗甸县| 桦川县| 诸暨市| 盐亭县| 马龙县| 博湖县| 睢宁县| 伊金霍洛旗| 马关县| 南雄市| 九龙县| 永昌县| 富平县| 班戈县| 察隅县| 庆阳市| 太保市| 高邑县| 怀仁县| 博客| 武乡县| 吴桥县| 修水县| 湖北省|