Grokking Node.js
0% completed
Event-Driven Programming with EventEmitter
Calling emit does not schedule anything for later. Many readers expect events to work like the callbacks of the previous lessons, which wait for the event loop. Run the following script and compare the order of the output with that expectation:
const EventEmitter = require('events'); const orders = new EventEmitter(); orders.on('placed', () => { console.log('Listener: an order was placed'); }); console.log('Before emit'); orders.emit('placed'); console.log('After emit');
Before emit Listener: an order was placed After emit
.....
.....
.....
Like the course? Get enrolled and start learning!
Reading Progress
0%