Created
November 10, 2014 14:22
-
-
Save DWboutin/cd64a60f560f472b71df to your computer and use it in GitHub Desktop.
Create custom event with Node.js
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
var events = require('events'); | |
var emitter = new events.EventEmitter(); | |
function taskStatus(status) { | |
if (status === 'done') { | |
emitter.emit('done'); | |
} else if (status === 'doing') { | |
emitter.emit('doing'); | |
} | |
} | |
emitter.on('done', function() { | |
console.log('The task given is done!'); | |
}); | |
emitter.on('doing', function() { | |
console.log('Doing the given task!'); | |
}); | |
setTimeout(taskStatus, 200, 'done'); | |
setTimeout(taskStatus, 500, 'doing'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment