async wait

async 用于申明一个 function 是异步的,而 await 用于等待一个异步方法执行完成。

即先执行async,async 函数返回的是一个 Promise 对象,

然后进行await。

async function doIt() {
    console.time("doIt");
    const time1 = 300;
    const time2 = await step1(time1);
    const time3 = await step2(time2);
    const result = await step3(time3);
    console.log(`result is ${result}`);
    console.timeEnd("doIt");
}

doIt();


猜你喜欢

转载自blog.csdn.net/ttn456456/article/details/79554367