How to Check Whether an Angular $q promise Is Resolved

angularjs, promise, q

Solution

I guess this was added in a recent version of Angular but there seems to be now an $$state object on the promise:

 var deferred = $q.defer();
 console.log(deferred.promise.$$state.status); // 0
 deferred.resolve();
 console.log(deferred.promise.$$state.status); //1 

As noted in the comments this is not recommended as it might break when upgrading your Angular version.

Problem

I understand that typically one would just attach continuation code with a `then()` call and chain behaviour when using promises. However, I want to kick off a promise-wrapped asynchronous call and then separately kick off a 3-second `$timeout()` so I can take a UI action, ONLY IF the original promise has not yet completed. (I anticipate that this would only happen on slow connections, mobile devices on 3G, etc.) Given a promise, can I check whether it's complete or not without blocking or waiting?

Original source

Related problems