Here is cleaner solutions using async/await
:
// Set this to some high value
// current value 300000 = 5 minutes, which should be good in most cases!
const _dummy = setInterval(() => {}, 300000);
function performRequest(url) {
return new Promise( (resolve) => { pm.sendRequest(url, (err, res) => {
// We are not checking for errors
// If you want you can read the err object to do do some error handling
setTimeout((res) => { return resolve(res); }, 2000); // Wait for 2 seconds before returning the result.
// if no delay is required remove the above line and uncomment the following
// return resolve(res);
});
});
}
// I haven't defined requestList in this example, it should be set as described in the previous post
(async function () {
for(let idx = 0; idx < requestList.length; idx++) {
console.log("Calling:", requestList[idx]);
let response = await performRequest(requestList[idx]);
console.log("response:", response);
}
clearInterval(_dummy);
}) ();