I’m trying to run this while loop in a syncronous way, i need this function to control a process checking his status querying the endpoint every x seconds after launching the process from a button on the UI.
It seems to be not running it correctly or else I’m not controlling it properly with the right code because it is not logging anything in the console. I am not experienced in javascript, could someone tell me what would be the best way to do it?
Thanks,
Ivan
current code:
export default {
executeRoutine2: () => {
function loopScanStatus() {
function task() {
setTimeout(function() {
DP_REQUEST_SCAN_STATUS.run();
}, 5000);
}
while (true) {
task();
console.log(DP_REQUEST_SCAN_STATUS.data);
if (DP_REQUEST_SCAN_STATUS.data === "FINISHED") {
console.log("ENDED")
}
}
}
DP_REQUEST_DATASTORE_SCAN.run()
.then(() => loopScanStatus());
}
}
@cripsisxyz I wasn’t able to view logs on the Appsmith console. I’ll create a GitHub issue for this. However, I was able to view logs on the browser console. Could you confirm if you’re able to view the same?
export default {
executeRoutine2: () => {
async function loopScanStatus() {
while (true) {
const data = await DP_REQUEST_SCAN_STATUS.run();
console.log(data);
if (data === "FINISHED") {
console.log("ENDED")
break;
}
}
}
DP_REQUEST_DATASTORE_SCAN.run()
.then(() => loopScanStatus());
}
}
I have not been able to make the loop have a delay, but since it is waiting each time for the response from the API, it no longer executes as frequently