I'm returning a promise from a function like this:
resultPromise = dgps.utils.save(opportunity, '/api/Opportunity/Save', opportunity.dirtyFlag).then(function () {
self.checklist.saveChecklist(opportunity).then(function () {
self.competitor.save(opportunity.selectedCompetitor()).then(function ... etc.
return resultPromise;
Let's say the above function is called save.
In the calling function I want to do wait for the entire chain to complete and then do something. My code there looks like this:
var savePromise = self.save();
savePromise.then(function() {
console.log('aftersave');
});
The result is that 'aftersave' is send to the console while the chain of promises is still running.
How can I do something after the whole chain is complete?