Skip to content

Instantly share code, notes, and snippets.

@josedigital
Created October 21, 2016 03:45
Show Gist options
  • Save josedigital/75a9ea4dd5a46302ada16ed5449196a2 to your computer and use it in GitHub Desktop.
Save josedigital/75a9ea4dd5a46302ada16ed5449196a2 to your computer and use it in GitHub Desktop.
// how a promise works in javascript
function doWorkPromise(data) {
return new Promise(function(resolve, reject) {
resolve('everything worked');
reject({
error: 'something bad happened'
});
});
}
// the following code is basically a function (called 'then') with 2 functions as args
// function(data).then(func1() {}, func2() {});
doWorkPromise('some data').then(function(data) {
console.log(data);
}, function(error) {
console.log(error);
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment