Showing
11 changed files
with
76 additions
and
0 deletions
File mode changed
1 | +var events = require('events'); | ||
2 | +var eventEmitter = new events.EventEmitter(); | ||
3 | +var connectHandler = function connected() { | ||
4 | + console.log('connection successful.'); | ||
5 | + eventEmitter.emit('data_received'); | ||
6 | +} | ||
7 | + | ||
8 | +eventEmitter.on('connection', connectHandler); | ||
9 | + | ||
10 | +eventEmitter.on('data_received', function(){ | ||
11 | + console.log('data received successfully.'); | ||
12 | +}); | ||
13 | + | ||
14 | +eventEmitter.emit('connection'); | ||
15 | +console.log("Program Ended."); |
1 | +var events = require('events'); | ||
2 | +var eventEmitter = new events.EventEmitter(); | ||
3 | +var listner1 = function listner1() { | ||
4 | +console.log('listner1 executed.'); | ||
5 | +} | ||
6 | +var listner2 = function listner2() { | ||
7 | +console.log('listner2 executed.'); | ||
8 | +} | ||
9 | + | ||
10 | +eventEmitter.addListener('connection', listner1); | ||
11 | +eventEmitter.on('connection', listner2); | ||
12 | +var eventListeners = require('events').EventEmitter.listenerCount(eventEmitter,'connection'); | ||
13 | +console.log(eventListeners + " Listner(s) listening to connection event"); | ||
14 | + | ||
15 | +eventEmitter.emit('connection'); | ||
16 | +eventEmitter.removeListener('connection', listner1); | ||
17 | +console.log("Listner1 will not listen now."); | ||
18 | + | ||
19 | +eventEmitter.emit('connection'); | ||
20 | +eventListeners = require('events').EventEmitter.listenerCount(eventEmitter,'connection'); | ||
21 | +console.log(eventListeners + " Listner(s) listening to connection event"); | ||
22 | +console.log("Program Ended."); |
LectureNotes/Chapter08.pdf
0 → 100644
No preview for this file type
LectureNotes/Experiments08.pdf
0 → 100644
No preview for this file type
-
Please register or login to post a comment