Last active
August 29, 2015 14:19
-
-
Save rehia/b4eace8230baabf348fc to your computer and use it in GitHub Desktop.
Problem with promises : is it the right way ?
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
var client, payment; | |
return clientDao.get(id) | |
.then(function (foundClient) { | |
client = foundClient; | |
return paymentDao.get(paymentId); | |
}).then(function(foundPayment) { | |
client.credit(payment.amount); | |
payment.cancel(); | |
return clientDao.save(client); | |
}).then(function() { | |
return paymentDao.save(payment); | |
}).then(function () { | |
client.flush(); | |
payment.flush(); | |
}, function (error) { | |
eventBus.publish('payment_cancel_error', { | |
error: error, | |
client: client || {id: id}, | |
payment: payment || {id: paymentId} | |
}); | |
}); |
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
var client; | |
return clientDao.get(id) | |
.then(function (foundClient) { | |
client = foundClient; | |
client.debit(amount); | |
return clientDao.save(client); | |
}).then(function () { | |
client.flush(); | |
}, function (error) { | |
eventBus.publish('client_debited_error', { | |
error: error, | |
client: client || {id: id} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment