Skip to content

Instantly share code, notes, and snippets.

@craigpalermo
Created August 6, 2015 04:00
Show Gist options
  • Save craigpalermo/b89f2971c4107233d7b8 to your computer and use it in GitHub Desktop.
Save craigpalermo/b89f2971c4107233d7b8 to your computer and use it in GitHub Desktop.
JavaScript example of using promises and callbacks
var promiser = function (callback) {
var promise = new Promise(function(resolve, reject){
console.log("Promise created");
window.setTimeout(function(){
resolve("Hello from Promise Land");
}, 3000);
});
promise.then(function(){
callback();
});
};
var myCallback = function () {
console.log("Promise resolved");
};
promiser(myCallback);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment