• async异步函数的执行顺序


     1 async function async1(){
     2     console.log('async1 start') //2
     3     await async2()
     4     //await async2()后面的内容可以看做是callback里得内容即是异步
     5     //类似eventloop,settimeout
     6     //Promise.resolve().then(()=>{console.log(async1 end)})
     7     console.log('async1 end') //5
     8 }
     9 
    10 async function async2(){
    11     console.log('async2') //3
    12 }
    13 
    14 console.log('script start') //1
    15 async1()
    16 console.log('script end') //4

     变体

     1 async function async1(){
     2     console.log('async1 start') //2
     3     await async2()
     4     //后面都是异步回调callback的内容
     5         console.log('async1 end') //4
     6         await async3()
     7             console.log('async2 end') //6
     8 }
     9 
    10 async function async2(){
    11     console.log('async2') //3
    12 }
    13 
    14 async function async3(){
    15     console.log('async3') //5
    16 }
    17 
    18 console.log('script start') //1
    19 async1()
    20 console.log('script end') //4

     异步函数 返回的是一个promise  内部await相当于then,await后面的是异步回调内容

  • 相关阅读:
    Good Substrings CodeForces
    Watto and Mechanism Codeforces Round #291 (Div. 2)
    Codeforces Round #487 (Div. 2) A Mist of Florescence (暴力构造)
    Oulipo HDU
    POJ
    求值2 组合数公式题目
    URAL
    SCU
    【转】phpcms授课学习
    WordPress文章浏览历史插件
  • 原文地址:https://www.cnblogs.com/musicbird/p/16111175.html
Copyright © 2020-2023  润新知