Skip to content

Instantly share code, notes, and snippets.

@Nepoxx
Created February 25, 2015 22:38
Show Gist options
  • Save Nepoxx/5b4a9671ec0fdb9246bc to your computer and use it in GitHub Desktop.
Save Nepoxx/5b4a9671ec0fdb9246bc to your computer and use it in GitHub Desktop.
//First way
Promise.resolve(userModel.findOneAndUpdate({uid: myUserId}, updatedUserModel, {
upsert: true,
"new": false
}).exec())
.then(function (user) {
...
})
.spread(function markNotificationsAsRead(unreadNotifications) {
...
})
.then(function sendResponse(unreadNotifications) {
...
})
.then(null, function (err) {
//handle error
});
//Second way
userModel.findOneAndUpdate({uid: myUserId}, updatedUserModel, {
upsert: true,
"new": false
}).exec()
.then(function (user) {
...
})
.spread(function markNotificationsAsRead(unreadNotifications) {
...
})
.then(function sendResponse(unreadNotifications) {
...
})
.then(null, function (err) {
//handle error
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment