Skip to content

Instantly share code, notes, and snippets.

Created March 28, 2014 16:44
Show Gist options
  • Save anonymous/9837338 to your computer and use it in GitHub Desktop.
Save anonymous/9837338 to your computer and use it in GitHub Desktop.
Basic ES6 Promise Example
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