0

Thanks to the lovely person who provided me this answer

Angular - Multiple $http.get Requests for Data

I now use $q quite often when making http requests.

My question now is should I also be it using when firing several functions when a controller is activated?

Say for instance the first few lines of my controller has

functionOne()
functionTwo()
functionThree() 

should I instead be using

$q.all([
        functionOne();
        functionTwo();
        functionThree();
    ]);

even if the functions in question do not return a promise, and are not making http calls.

Community
  • 1
  • 1
user2085143
  • 4,162
  • 7
  • 39
  • 68
  • Well .. if they don't return promises and you don't care if all have been executed in order to take further steps ... then why would you ? – sirrocco Nov 19 '15 at 17:25
  • Why would you? Do `functionOne`, `functionTwo` and `functionThree` execute asynchronous code that you need to wait for in order to continue execution? – Marcelo Nov 19 '15 at 17:25
  • Putting synchronous functions in a `q.all` call will convert them to promises. You can't guarantee which order those functions will be executed by the `$q` service. You are guaranteed that `$q` service will wait until **all** the functions are finished before executing the registered `.then` methods. – georgeawg Nov 19 '15 at 17:54
  • Plus the way you're using it, you're essentially doing $q.all([value_from_functionone, value_from_functiontwo .. etc]) .. so it doesn't make much sense – sirrocco Nov 19 '15 at 18:54
  • IMO you should not, unless you expect it will add some value at one point it only makes the code less readable. We actually run into some serious issues because of developers having troubles to deal with promises as its not natural for most. Keep it simple and use q when necessary. – mikus Nov 20 '15 at 14:32

0 Answers0