I have a very quirky api that can only handle a single request at a time. Therefore, I need to ensure that every time a request is made, it goes into a queue, and that queue
My two queues:
code:
app.factory('QueueHttp', ($http, $q) => {
let promise = $q.resolve();
return (conf) => {
let next = () => {
return $http(conf);
};
return promise = promise.then(next);
};
});
usage:
return QueueHttp({
url: url,
method: 'GET'
});
code:
app.factory('DelayHttp', ($http, $timeout) => {
let counter = 0,
delay = 100;
return (conf) => {
counter += 1;
return $timeout(() => {
counter -= 1;
return $http(conf);
}, counter * delay);
};
});
usage:
return DelayHttp({
url: url,
method: 'GET'
});