When dealing with asynchronous behavior in a function, I often find myself creating a deferred and returning a promise. For example:
var deferred = $q.defer();
//...some async operation
return deferred.promise;
However, sometimes I want to skip the async activity and immediately return a resolved promise. Is there a more efficient way to achieve this?
For instance, would it be appropriate to use the following shortcut at the beginning of my function:
if (shouldShortcut) {
return $q.when(true);
}