如何setInterval在下面的示例中运行异步函数? setInterval(async () => {
}, millisPerHour);
1 回答
智慧大石
TA贡献1946条经验 获得超3个赞
尝试使用此代码
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/async_function
function resolveAfter2Seconds() {
return new Promise(resolve => {
setTimeout(() => {
resolve('resolved');
}, 2000);
});
}
async function asyncCall() {
console.log('calling');
const result = await resolveAfter2Seconds();
console.log(result);
// expected output: "resolved"
}
asyncCall();`
添加回答
举报
0/150
提交
取消