Promise
async 函数的描述
function sleep(duration) {
return new Promise(resolve => {
setTimeout(resolve, duration);
})
}
async function doa(value, duration) {
console.log(value);
await sleep(duration);
}
let count = 2;
void async function init() {
while (true && count--) {
await doa(1, 1000)
await doa(2, 2000)
await doa(3, 3000)
}
}
init()最后更新于