I want to wait 3 second to return my value, but after I ran the function what I got was
result
then wait 3 seconds
function testFn() {
setTimeout(() => console.log('wait 3 seconds'), 3000);
return 'result';
}
testFn();
I want to wait 5 seconds to send the request if I got 'PEDING' from my first response,
so I wrote a recursion function to do it, but it doesn't work
it never wait 5 seconds then send the request.
axios.post("api/A", searchInfo)
.then(response => {
if(response.data.message==='PENDING .'){
const body={
}
setInterval(() => {
console.log('wait 5 seconds first time')
}, 5000);
return APOSTRequest(body,dispatch,5000);
}
})
.catch(err => {
console.log("err", err);
});
const APOSTRequest=(body,dispatch)=>{
axios.post("api/A", body)
.then(response => {
if(response.data.message==="PENDIG."){
setInterval(() => {
console.log('wait 5 seconds 2nd')
}, 5000);
return setTimeout(APOSTRequest(body,dispatch), 5000);
}else{
}
})
.catch(err => {
console.log("err", err);
});
}```