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

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.

主站蜘蛛池模板: 靖安县| 普安县| 金堂县| 博罗县| 惠州市| 札达县| 理塘县| 太湖县| 比如县| 海城市| 临高县| 临夏县| 林州市| 水城县| 桃园市| 青龙| 黔江区| 沿河| 如皋市| 广元市| 蒲城县| 栾城县| 贵溪市| 溆浦县| 错那县| 綦江县| 葵青区| 安平县| 台南市| 仲巴县| 墨玉县| 米泉市| 绥江县| 廉江市| 五华县| 宜昌市| 潼南县| 菏泽市| 丰镇市| 水富县| 都昌县|