Last active
August 29, 2015 14:23
-
-
Save mlms13/953aefdc5e5ca0deee2f to your computer and use it in GitHub Desktop.
Promises and Events! and Pseudo-Code!
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
function tellMeWhenThatThingHappens() { | |
var promise = new Promise(function (resolve, reject) { | |
window.addEventListener('thatAwesomeThingHappens', function () { | |
resolve(/* maybe with some data here */); | |
}); | |
// if it's possible for that awesome thing to fail... | |
window.addEventListener('refusingToBeAwesome', function () { | |
reject(/* maybe with an error */); | |
}); | |
}); | |
// do something that might trigger that event | |
window.maybeMakeAwesomeThingsHappen(); | |
return promise; | |
} | |
tellMeWhenThatThingHappens().then(function (data) { | |
// do something! | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment