Assume we have a simple front end and (let's assume Angular if it matters) and a back end app. Say the front end app does a get
request. Usually the angular repository makes an $http.get
request which returns a promise (angular 1) or an observable that can be converted to a promise (angular 2 or 4), and then the repository returns that promise. Then the angular service will look something like
repository.makeTheGetCall().then(function (response) {
// process response
});
This is fine usually.
1) But what if all the logic on the service is dependent on this 1 call? Then we've essentially nested the entirety of the service within a .then clause.
2) Or what if based on the response of the first Get request, we make another request. And based on that response, we make another request, and so on. Then we will have a bunch of then clauses chained.
Neither situations seems that rare, and both result in what appears to be 'ugly' code. Is there any other practice that can be used so to allow asynchronous calls but without having to return promises from the repository layer to the service layer?
Thank you :)