title: Immediately return a resolved promise using AngularJS
body: <p>I'm trying to get my head around promises in JavaScript (in particular AngularJS).</p>
  
  <p>I have a function in a service, let's call it <code>fooService</code>, that checks if we've loaded some data. If it has, I just want it to return, and if we haven't, we need to load the data and return a promise:</p>
  
  <pre><code>this.update = function(data_loaded) {
      if (data_loaded) return;  // We've loaded the data, no need to update
  
      var promise = Restangular.all('someBase').customGet('foo/bar').then(function(data) {
          // Do something with the data here
      }
  
      return promise;
  }
  </code></pre>
  
  <p>I have another function that then calls the <code>update</code> function of <code>fooService</code> like so:</p>
  
  <pre><code>fooService.update(data_loaded).then(function() {
      // Do something here when update is finished
  })
  </code></pre>
  
  <p>My issue here is that if we don't need to load the data in the <code>update</code> function, a promise isn't returned, so the <code>.then()</code> is not called in my other function. What should the approach be here - basically I want to return a resolved promise immediately from the <code>update()</code> function if we do not need to get data from the Restangular call?</p>