异步解决之async/await

async/await

  相对来说最简单的写法,async和await  这一堆组合最好用。

  **写法**
        跟generator生成器写法类似, 在函数声明的时候 async function 函数名(){},函数体内 在对象前使用await.

实例

async function initData() {
    let categoryList = await getShopCategory();
    let goods = await getGoods(categoryList[0].id)
    let comment = await getComment(goods[0].id);
    return comment;
}

initData().then(res => {
    console.log(res);
})

实现原理在上一节的生成器generator 递归可见

原文地址:https://www.cnblogs.com/qianqiang0703/p/13610145.html