他不输出 console.log
, 如果屏蔽 main
方法则会输出,这是为什么呢?
如何让他不堵塞呢?
function sleep(numberMillis) {
var now = new Date();
var exitTime = now.getTime() + numberMillis;
// eslint-disable-next-line no-constant-condition
while (true) {
now = new Date();
if (now.getTime() > exitTime) return;
}
}
async function main() {
while (true) {
await sleep(3000);
}
}
main();
setInterval(() => {
console.log("---");
}, 1000);
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…