Created
May 5, 2016 19:08
-
-
Save ds0nt/c6f568e1f13c46db1928ad8bcb55c1ff to your computer and use it in GitHub Desktop.
This file contains 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 EventEmitter = require("events").EventEmitter | |
var events = new EventEmitter() | |
var deferred = Promise.defer(); | |
events.once("ready", function() { | |
console.log("events once callback") | |
deferred.resolve("how amazing") | |
}) | |
console.log("waiting 3 seconds"); | |
setTimeout(function() { | |
events.emit("ready") | |
}, 3000) | |
module.exports = { | |
ready: deferred.promise | |
} |
This file contains 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 p = require('./eventpromise.js') | |
p.ready.then(function(res) { | |
console.log('promise then fired', res) | |
}).catch(function(err) { | |
console.error('promise catch fired') | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment