1. 1.await会执行promiseresolve的状态,相当于执行了then函数
    1. async function a1(){
    2. console.log("a1-start")
    3. await a2();
    4. console.log("a1-end")
    5. }
    6. async function a2(){
    7. console.log("a2")
    8. }
    9. a1();
    10. console.log("end-script")

    await会将函数阻塞,会优先执行同步不耗时的任务

    1. async function show(){
    2. console.log("start");
    3. await mid();
    4. console.log("end")
    5. }
    6. async function mid(){
    7. console.log("mid")
    8. }
    9. show()
    10. console.log("line")
    1. async function a1() {
    2. console.log("a1-start")
    3. await a2();
    4. console.log("a1-end")
    5. }
    6. async function a2() {
    7. console.log("a2")
    8. }
    9. a1();
    10. console.log("end-script")
    11. new Promise((resolve) => {
    12. console.log("a3")
    13. resolve()
    14. }).then(() => {
    15. console.log("a4")
    16. })

    await后面的代码可以看做是一个异步回调