I have the below code where checkReady() is called every 5 seconds until the response comes back as true.
But when I test this function, it does not appear to be waiting 5 seconds between each call to checkReady(). How can I correctly implement this to wait between each call ?
async isReady(ID) {
try {
const checkReady = async (value) => {
console.log('checkReady = ' + value);
if (value > 0) {
let response = await client.get(`/user/account/isReady/${ID}`);
let ready = response.data;
if (ready) {
this.Ready = true;
return;
}
setTimeout(await checkReady(value - 1), 5000);
}
}
await checkReady(10);
}
catch (e) {
console.error(e);
}
}