title: Can you resolve an angularjs promise before you return it?
body: <p>I am trying to write a function that returns a promise. But there are times when the information requested is available immediately. I want to wrap it in a promise so that the consumer doesn't need to make a decision.</p>
  
  <pre><code>function getSomething(id) {
      if (Cache[id]) {
          var deferred = $q.defer();
          deferred.resolve(Cache[id]); // &lt;-- Can I do this?
          return deferred.promise;
      } else {
          return $http.get('/someUrl', {id:id});
      }
  }
  </code></pre>
  
  <p>And use it like this:</p>
  
  <pre><code>somethingService.getSomething(5).then(function(thing) {
      alert(thing);
  });
  </code></pre>
  
  <p>The problem is that the callback does not execute for the pre-resolved promise. Is this a legitimate thing to do? Is there a better way to handle this situation?</p>