JavaScript Alternative to promises of asynchronous callouts?

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 :)

Answer:1

How do I get the size (in bytes) of a bufferd image in javascript? I am not allowed to trust the file size in the client side, and need to verify in the backend as part of upload validation. My setup ...

How do I get the size (in bytes) of a bufferd image in javascript? I am not allowed to trust the file size in the client side, and need to verify in the backend as part of upload validation. My setup ...

  1. byte buffer size
  2. java bytebuffer size
  3. byte buffer size golang
  4. new byte buffer_size
  5. byte array buffer size
  6. byte buffer size c#

There is a vuejs component called my-comp with a given data that I want to iterate on its elements and print them: <my-comp json-data='[{"id":1,"text":"Hello"},{"id":2,"text":"World"}]' inline-...

There is a vuejs component called my-comp with a given data that I want to iterate on its elements and print them: <my-comp json-data='[{"id":1,"text":"Hello"},{"id":2,"text":"World"}]' inline-...

I have a utility function to check whether a variable is not null or undefined, and I want TypeScript to narrow down the input variable if it passes the check, for example: public init(input?: string)...

I have a utility function to check whether a variable is not null or undefined, and I want TypeScript to narrow down the input variable if it passes the check, for example: public init(input?: string)...

  1. narrow this down
  2. narrow down this topic
  3. narrow down synonym
  4. narrow down meaning
  5. narrow down crossword
  6. narrow down crossword clue
  7. narrow down thesaurus
  8. narrow down the scope
  9. narrow down examples
  10. narrow down in spanish
  11. narrow down definition
  12. narrow down meaning in hindi
  13. narrow down the issue
  14. narrow down in french
  15. narrow down colleges
  16. narrow down nyt crossword
  17. narrow down in a sentence
  18. narrow down crossword puzzle clue
  19. narrow down the search
  20. narrow down topic examples

I need to create a preview of the fields created dynamically in a form. If I click preview button the fields displayed in form should displayed in using AngularJS. Are there any possibilities to do ...

I need to create a preview of the fields created dynamically in a form. If I click preview button the fields displayed in form should displayed in using AngularJS. Are there any possibilities to do ...