I have a multi-step process that I'd like to find a better pattern for. Let's say there's an order that you need to create revenue records for to eventually prepare an invoice. I have 4 calls to callback functions that need to happen in order. The callbacks are typically like the one here:
getRevenue(item.ID,
function(revenueRecords) //on success
{..do whatever to revenue here...},
function(errorMsg) //on failure
{..show error msg here...});
So in my code I need 4 of them like this:
getRevenue
getNewInvoice#
(create invoice details)
saveRevenue
(mark order as billed)
saveOrder
(alert user we succeeded)
Of course each one has to have a failure function as well and it gets pretty ugly. I'm aware that $q.defer can let me combine promises and only return when they are all complete, but this process requires the steps to be sequential. I wondered if there was a better pattern for solving multi-step sequential processes involving callbacks.