I have a function like:
function callApi(url){
return fetch(url).then(response => {return response.json()}
).then(response => {return response})
}
function myFunction() {
var status = null;
while (status != "complete") {
setTimeout(function(){
callApi('myurl').then(response => {
status = response.status
}
}, 5000)
}
Here I simply want to check if I am getting desired status from the api call.
Untill I get desired status from the api call I want to check on every 5 seconds..
But this is not working.. I have googled but not understood the solution according to my need. It would be very helpful if anyone could answer this.
I am new to javascript. I have looked somewhere about es6
promise.
It would be very great if someone could explain this ..
thank you