Skip to content

Instantly share code, notes, and snippets.

@gabrielizalo
Created July 8, 2017 00:19
Show Gist options
  • Save gabrielizalo/9e9a6a13dd6eba4494a4b4fc88bce9f1 to your computer and use it in GitHub Desktop.
Save gabrielizalo/9e9a6a13dd6eba4494a4b4fc88bce9f1 to your computer and use it in GitHub Desktop.
Javascript - Promises
// Definition
// ----------------
var p = new Promise(function(resolve, reject) {
// Do an async task async task and then...
if(/* good condition */) {
resolve('Success!');
}
else {
reject('Failure!');
}
});
// Usage
// ----------------
var p = new Promise(function(resolve, reject) {
p.then(function() {
/* do something with the result */
}).catch(function() {
/* error :( */
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment