Created
March 28, 2014 16:44
-
-
Save anonymous/9837338 to your computer and use it in GitHub Desktop.
Basic ES6 Promise Example
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 resolve(val) { | |
alert('Counted to ' + val); | |
return val; | |
} | |
function reject(reason) { | |
alert('Could not count'); | |
return reason; | |
} | |
function resolver(resolve, reject) { | |
setTimeout(function doneCounting() { | |
resolve(5); | |
}, 5000); | |
} | |
var countToFive = new Promise(resolver); | |
countToFive.then(resolve, reject); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment