Created
March 18, 2018 20:33
-
-
Save johnantoni/f13a55080b56aff41389c3e575928595 to your computer and use it in GitHub Desktop.
es6 promises
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const save = () => { | |
return new Promise((resolve, reject) => { | |
// access the db | |
// save the file | |
// when the file is saved successfully | |
// resolve with the saved document | |
resolve(doc) | |
// if there was an error | |
reject(err) | |
}) | |
} | |
save() // | |
{ | |
then: | |
catch: | |
} | |
// const user = new User() | |
// | |
// user | |
// .save() | |
// .then(function(doc) { | |
// | |
// }) | |
// .catch() | |
// | |
// | |
// | |
// { | |
// then: (doc) | |
// catch: (err) | |
// } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment