async 与 await

const doSometing = t => {
    return new Promise(resolve => {
        setTimeout(() => {
            resolve(t);
        }, t);
    });
};
const doSometing2 = t => {
    return t;
};

const fun = async () => {
    let d3 = await doSometing2(2500);
    console.log(d3); //不需要等待,直接输出2500
    let d2 = await doSometing(1500);   //阻塞1500毫秒后下面的代码才执行
    console.log(d2); //1500
    let d1 = await doSometing(1000);   //阻塞1000毫秒后下面的代码才执行
    console.log(d1); //1000

};
fun();

上一篇:基于mirai的pythonqq机器人(graia的使用)


下一篇:转载: async/await的实现原理