node. js Event Loop
The Nodejs event loop is a bit like the groove mechanism in QT.
//Introducing the Events modulevarEvents = require (' Events ');//Create a Eventemitter objectvarEventemitter =Newevents. Eventemitter ();//To create an event handlervarConnecthandler =functionconnected () {Console.log (' Connection succeeded. ‘); //Triggering data_received EventsEventemitter.emit (' data_received ');}//binding Connection Event handlersEventemitter.on (' Connection ', Connecthandler); //binding data_received events with anonymous functionsEventemitter.on (' data_received ',function() {Console.log (' Data received successfully. ‘);});//Triggering connection EventsEventemitter.emit (' Connection '); Console.log ("The program has finished executing. ");
You can see that it defines a eventemitter and then uses that object to connect the time handlers together. The event handler is invoked when the connection time starts, and the signal in Qt is very similar to the slot.
Mean Framework Learning notes (i)