sleep 函数
// Promise
const sleep = time => new Promise(resolve => setTimeout(resolve, time));
// ES5
function sleep(callback, time) {
setTimeout(callback, time);
}
async function test() {
for (let index = 0; index < 10; index++) {
console.log(index);
await sleep(2000);
}
}
test();