Skip to content

Instantly share code, notes, and snippets.

@AlejandroPerezMartin
Created April 8, 2016 07:59
Show Gist options
  • Save AlejandroPerezMartin/99de49e2494bac0a231a8155bbcf9a0b to your computer and use it in GitHub Desktop.
Save AlejandroPerezMartin/99de49e2494bac0a231a8155bbcf9a0b to your computer and use it in GitHub Desktop.
JavaScript Promises test
window.onload = function() {
init();
otherFn();
}
function init() {
var myPromise = new Promise(function(resolve, reject){
setTimeout(function() {
resolve("Promise called!");
}, 1000);
});
myPromise.then(function (result) {
console.log(result);
})
.catch(function(reason){
console.error("Rejected because: " + reason);
});
}
function otherFn(){
console.log("Other code executed");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment