Skip to content

Instantly share code, notes, and snippets.

@Ibro
Created April 27, 2017 18:24
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 Ibro/abcae31e7eab39e5377850a7679e518a to your computer and use it in GitHub Desktop.
Save Ibro/abcae31e7eab39e5377850a7679e518a to your computer and use it in GitHub Desktop.
Promise JavaScript - Coding Blast - www.codingblast.com
function iGiveYouAPromise(value: number) {
return new Promise(function (resolve, reject) {
if (value === 4141) {
reject('Number is too weird..')
} else {
setTimeout(function () {
resolve('Success!');
}, 1500);
}
});
}
let promise = iGiveYouAPromise(151);
promise.then(function (resp) {
console.log('inside of success callback! value:', resp);
}, function (err) {
console.log('inside of error callback! error:', err);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment