使用的setInterval()[重复]无限异步环
这个问题已经在这里有一个答案:
- Combination of async function + await + setTimeout 7个回答
setInterval
是不正确的工具,因为它是不知道的承诺,不能保持正确的控制流。
它可以用无限循环async
功能:
async function execute1() {
while (true) {
await new Promise(resolve => setTimeout(resolve, 500));
// ...do some async work...
}
}
execute1();
与本文相关的文章
评论列表(0)
- 暂无评论