I am working on a function that needs to check a value. If the value doesn't exist, it should wait for 5 seconds and then call itself again. The code snippet is provided below, but it seems like it's not waiting for the specified time and keeps executing immediately. How can I fix this issue?
loadAPI(status: string) {
.....
if (this.result === "done") {
.....
}
else
{
this.sleep(5000);
loadAPI(this.status);
}
}});
}
sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}