【发布时间】:2018-02-04 10:03:37
【问题描述】:
我们的团队正在开发一个网络应用/游戏,如果条件为真,我们希望每 8 秒调用一次 API。 此过程由启动填充方法的按钮触发
async autoLoad() {
const timer = await 8;
console.log('debug consolelog')
const result = await this.UpdateProfile();
}
togglePopulate() {
const status = this.state.autoLoad;
if (status === true) {
this.setState({ autoLoad: false });
} else {
this.setState({ autoLoad: true });
this.autoLoad();
}
}
我们的理解是,这将每 8 秒在后台运行一次“UpdateProfile()”函数。然而,结果是我们的整个网页被锁定并且 UpdateProfile(或调试 console.log)没有运行。
有人知道我们做错了什么吗? (或者如果我们尝试做的事情是可能的?)
【问题讨论】:
标签: javascript reactjs async-await