I have a pre-existing non-Angular API library in my project. It has a .request
method which returns jQuery.Deferred promises. I created a simple Angular service
Generally the better approach is to cast whatever object you do have into an Angular promise.
The concept of assimilating thenables is part of the Promises/A+ specification. Most promise libraries have a way to do this. It's what allows for awesome interop between promise implementations and a uniform API.
For this, $q uses .when
:
Wraps an object that might be a value or a (3rd party) then-able promise into a $q promise. This is useful when you are dealing with an object that might or might not be a promise, or if the promise comes from a source that can't be trusted.
It uses the concept of thenables to convert a 'non trusted' promise into a $q promise.
So all you have to do is
var p = $q.when(value); // p is now always a $q promise
// if it already was one - no harm