Looking to integrate a web API with JavaScript/AngularJS 1.x on a timed interval due to rate limiting. The code provided attempts to achieve this by utilizing a list of objects called RecordList
and a function called setDelay
that introduces delays with the setTimeout
method.
The issue arises when attempting to determine if all promises within the setTimeout
function have been successfully resolved. Traditional methods such as Promise.all
and $q.all
don't work seamlessly in conjunction with setTimeout
. Any suggestions for an alternative approach?
var waitInterval = 300;
var promiseArray = [];
function setDelay(obj, s) {
setTimeout(function() {
var SomePromise = $http.post('odataURI', obj).then(function success(result) {
//resolve(result);
});
promiseArray.push(SomePromise);
}, waitInterval * s);
}
for (var s = 1; s <= RecordList.length; s++) {
setDelay(RecordList[s - 1], s);
}