DIEA
2022-12-02 16:21:06
如何setInterval在下面的示例中運(yùn)行異步函數(shù)? setInterval(async () => {
}, millisPerHour);
1 回答

智慧大石
TA貢獻(xiàn)1946條經(jīng)驗(yàn) 獲得超3個(gè)贊
嘗試使用此代碼
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();`
添加回答
舉報(bào)
0/150
提交
取消