Last active
May 15, 2018 14:54
-
-
Save NickNaso/52ca8c46679faaebebe6fe76f9f7f657 to your computer and use it in GitHub Desktop.
How to use Event Emitter
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 'use strict' | |
| const { EventEmitter } = require('events') | |
| function print(evt) { | |
| console.log('#####') | |
| console.log('Event: ', evt.name) | |
| if (evt.data) { | |
| console.log(evt.data) | |
| } | |
| console.log('#####') | |
| } | |
| const ee = new EventEmitter() | |
| ee.on('start', print) | |
| ee.on('data', print) | |
| ee.on('end', print) | |
| ee.emit('start', { name: 'start' }) | |
| ee.emit('data', { name: 'data', data: 'EVENT DATA ...' }) | |
| ee.emit('end', { name: 'end'}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment