Here, you will need to add your URL calling code tho.
let arrUrls = [
["URL1", 4],
["URL2", 10],
["URL3", 8],
["URL4", 9],
["URL5", 6]
];
let sendNum = 0;
function callUrl(url, rpt){
for (let i = 0; i < rpt; i++) {
// calling code
console.log(`called ${url} - ${i}/${sendNum}`);
}
};
let x = 0;
while(x<4) // Change this to while(true) for infinite loop
{
sendNum = 0;
arrUrls.forEach(u => {
sendNum++;
callUrl(u[0], u[1]);
});
x++;
}
As per comments from guest. This is a more UI friendly version. Also I added a 3sec sleep and a stop button for convenience.
document.querySelector('button').addEventListener('click', (e) => {
if(interval !== undefined) {
clearInterval(interval);
console.log('Stopped !!');
}
});
let arrUrls = [
["URL1", 4],
["URL2", 10],
["URL3", 8],
["URL4", 9],
["URL5", 6]
];
let sendNum = 0;
let interval = undefined;
function callUrl(url, rpt) {
let count = 0;
for (let i = 0; i < rpt; i++) {
// calling code
count++;
}
console.log(`called ${url} - ${count} times - on loop: ${sendNum}`);
};
interval = setInterval(() => // Change this to while(true) for infinite loop
{
console.clear();
sendNum++;
arrUrls.forEach(u => {
callUrl(u[0], u[1]);
});
}, 3000);
<button>Stop Me</button>
7
solved Unstoppable loop [closed]