p() {
return new Promise((resolve, reject) => {
setTimeout(() => {
resolve("settimeout")
}, 2000);
});
},
async f() {
const that = this
const t = setInterval(async function() {
console.log('setInterval')
const x =await that.p();
console.log(x)
}, 2000);
},
setInterval没有等待setTimeout就直接进入下一轮
setInterval
只是调用函数而已,函数是否执行完它不关心,所以到时候就继续调用了。