我有一个箭头函数,它被调用cDM
以每 20 秒使用setTimeout()
. 该setTimeout()
方法永远不会像它应该的那样向服务器发出另一个请求。所以我认为代码永远不会到达。我不确定如何修改它以便达到该方法。
componentDidMount() {
//get request to /schedules
//update state with response data
this.getUpdatedStatus();
}
getUpdatedStatus = () => {
//fetch updated status,
//list of arrays that are updated to state in `cDM`
const schedules = this.state.schedules;
Promise.all(
schedules
.map(schedule =>
axios({
method: "get",
url: schedule.selfUri,
headers: {
Accept: " someValue"
}
})
)
.then(response => {
if (response.data.data[0].status !== "Complete") {
this.timeout = setTimeout(() => this.getUpdatedStatus(), 20000);
}
console.log(response);
this.setState(
{
scheduleStatus: response.data.data[0].status,
},
() => {
console.log(this.state.scheduleStatus);
}
);
})
).catch(error => console.log(error.response));
};