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

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.

主站蜘蛛池模板: 长阳| 德令哈市| 海兴县| 阿拉尔市| 潍坊市| 屯门区| 张家港市| 呼玛县| 沅陵县| 洛浦县| 临西县| 天长市| 阳信县| 上饶市| 鄂伦春自治旗| 内丘县| 永登县| 武定县| 河池市| 柘荣县| 北票市| 兴义市| 清丰县| 台安县| 日土县| 汉川市| 蛟河市| 桂阳县| 阿巴嘎旗| 南皮县| 湖南省| 云霄县| 天镇县| 龙山县| 甘德县| 涞源县| 肥西县| 元谋县| 延长县| 临洮县| 巴彦淖尔市|