Listening for events
In the previous chapter we were introduced 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.
Instead, the primary purpose of this section is to discuss some lesser-known event sources—signals, child process communication, filesystem change events, and deferred execution.
Signals
In many ways, evented programming is like hardware interrupt programming. Interrupts do exactly what their name suggests. They use their ability to interrupt whatever a controller or the CPU or any other device is doing, demanding that their particular need be serviced immediately.
In fact, the Node process...