欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

async原理

程序员文章站 2022-06-12 22:49:04
...

async 用法

async function A() {
  let a = await 1;
  console.log(a);
  let b= await Promise.resolve(2);
  console.log(b);
  return 3;
}

转码理解

function A() {
  var a;
  var b;
  return new Promise(function(resolve){
    a = 1;
    console.log(a);
    resolve();
  }).then(function(){
    Promise.resolve(2).then(res => {
      b = 2;
      console.log(b)
    });
  }).then(() => 3)
}

转载于:https://www.jianshu.com/p/85ecdd461daa