Last active
January 15, 2019 14:01
-
-
Save bouchtaoui-dev/214d3794ca9ea2a3ef47ef52d608645d to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| /** | |
| * promise object | |
| */ | |
| function getUserWithId(id) { | |
| return new Promise((resolve, reject) => { | |
| // Look for a user with id in the database | |
| User.find({_id: id}, (user, err) => { | |
| if(err) return reject(err); | |
| // on success | |
| resolve(user); // from pending --> resolved | |
| }); | |
| }); | |
| } | |
| /** | |
| * | |
| */ | |
| getUserWithId(someId) | |
| .then(user => { | |
| // we got a successfull object, send it back to the user or | |
| // something like that. | |
| }) | |
| .catch(ex => { | |
| // send or throw an error | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment