Process is also an example of emitter. Can be used directly in the program.
//Listening 1Process.on ("AA",function(data,state) {Console.log (' Monitor 1 '); Console.log (Data+ ': ' +State );});//Event 1Process.emit ("AA", ' Launch ', ' Event 1 ');//Listening 2Process.on ("AA",function(data,state) {Console.log (' Monitor 2 '); Console.log (Data+ ': ' +State );});//Launch 2Process.emit ("AA", ' Launch ', ' Event 2 ');//only when the monitoring time has been registered to hear the launch of the event//when launching event 1, monitoring 1 is registered, monitoring 2 is not yet registered//when launching event 2, listening 1 and listening 2 are already registered, so the result of the program operation is://Listening 1//Launch: Event 1//Listening 1//Launch: Event 2//Listening 2//Launch: Event 2
Node. js event firing Monitoring mechanism