Skip to content

Instantly share code, notes, and snippets.

@Nahiduzzaman
Created April 29, 2017 19:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Nahiduzzaman/fb19759409c54d683266084c12c3cda4 to your computer and use it in GitHub Desktop.
Save Nahiduzzaman/fb19759409c54d683266084c12c3cda4 to your computer and use it in GitHub Desktop.
let myFirstPromise = new Promise((resolve, reject) => {
// We call resolve(...) when what we were doing async succeeded, and reject(...) when it failed.
// In this example, we use setTimeout(...) to simulate async code.
// In reality, you will probably be using something like XHR or an HTML5 API.
setTimeout(function(){
resolve("Good To go"); // Yay! Everything went well!
}, 1000);
});
myFirstPromise.then((response) => {
// successMessage is whatever we passed in the resolve(...) function above.
// It doesn't have to be a string, but if it is only a succeed message, it probably will be.
console.log(response);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment