I'm working on an application with a large amount of lazy data loading. I would like to prioritize http requests based on 'priority' param.

This is the concept of using it.

```
$http.get(url, {params: query, priority: 1})

```

I was thinking of using $http interceptors. Something like that:

```
 angular.module('myModule')
.factory('httpPriorityInterceptor', function ($interval, $q) {
    var requestStack = [];

    return {
        request: function (config) {

            config.priority = config.priority || 3;

            requestStack.push(config);
            requestStack.sort(sortByPriority);

            if (isFirstToGo(item)) return requestStack.pop();

            deferred = $q.defer();

            var intervalPromise = $interval(function(){

                if (isFirstToGo(item)) {
                    deferred.resolve(requestStack.pop());
                    $interval.cancel(intervalPromise);
                };

            }, 100);

            return deferred.promise;

        }   
    };
});

```

But I can't return promise here. Any ideas?