title: How to wait for async angularJS call to complete if concurrent call requested the data being still loaded?
body: <p>I have an angular service/resource combo that does async call to server to get User Preferences. It is called UserPreferencesService and got a method load:</p>
  
  <pre><code> /// UserPreferencesService.load method
   CommonService.asyncCall(UserPreferencesResource.getAll, {username: userName}).then(
              function (data) {
                  userPreferenceData = data;
    }
  </code></pre>
  
  <p>where asyncCall stands for trivial angular async server call that returns deferred.promise. It is called at some point. </p>
  
  <p>Same UserPreferencesService also has method getCurrentProject() to return these preferences to controllers that are interested in, with calling code:</p>
  
  <pre><code>var myControllerInit = function()
   {
          var prj = UserPreferencesService.getCurrentProject();
   }
  </code></pre>
  
  <p>I have a situation that some controller (that displays "current project" on screen) calls "getCurrentProject" WHILE "load" async call is in progress, so getCurrentProject does not return neeeded data, as these are not fully loaded yet.</p>
  
  <p>How I can make it so that UserPreferencesService.getCurrentProject() will "wait" till the request resolves, if it is underway, and only then return the value? I suppose I can try to use promises, and I would like to have elegant, angular-style solution to the problem.</p>