I have the following functionality and am unsuccessfully trying to add a pause after each request of 2 seconds as to not exceed the RPM threshold.
<cfoutput>
<script type="text/javascript" language="JavaScript">
// Convert ColdFusion variable to JS variable
#ToScript(Variables.resourceIds, "jsList")#
// Split list
var list = jsList.split(",");
// Loop through list
for (var i=0; i<list.length; i++) {
var pricingSearch = new XMLHttpRequest();
pricingSearch.open("GET", "doPricing.cfm?ID=" + list[i], false);
pricingSearch.onload = function (e) { };
pricingSearch.onerror = function (e) { };
pricingSearch.send(null);
console.log('Searching for Id ' + list[i] + '...');
setTimeout(function() {
// Wait for a couple seconds
}, 2000);
if (i == list.length) {
console.log('All done!');
}
}
</script>
</cfoutput>
This just doesn't appear to do anything as the loop completes as quickly as it can.
I'd even tried adapting the code to this:
for (var i=0; i<list.length; i++) {
setTimeout(function(list,i) {
var pricingSearch = new XMLHttpRequest();
pricingSearch.open("GET", "doPricing.cfm?ID=" + list[i], false);
pricingSearch.onload = function (e) { };
pricingSearch.onerror = function (e) { };
pricingSearch.send(null);
console.log('Searching for Resource Id ' + list[i] + '...');
if (i == list.length) {
console.log('All done!');
}
}, 2000);
}
But this also does not work :(
Does anyone else know of any other methods I can use to achieve this?
Thanks