在NodeJS中进行睡眠处理

使用async/await。

const sleep = msec => new Promise(resolve => setTimeout(resolve, msec));

(async () => {
    console.log('a');
    await sleep(1000);
    console.log('b');
    await sleep(1000);
    console.log('c');
    await sleep(1000);
    console.log('d');
    await sleep(1000);
})();

/**
a
b
c
d
**/
广告
将在 10 秒后关闭
bannerAds