SOURCE

// async & await 测试
function takelongtime(n) {
  return new Promise(resolve => {
    setTimeout(() => resolve(n + 200), n)
  })
}

function step1(n) {
  console.log(`step1 with ${n}`) 
  return takelongtime(n)
}

function step2(m, n) {
  console.log(`step2 with ${m} and ${n}`) 
  return takelongtime(m + n)
}

function step3(k, m, n) {
  console.log(`step3 with ${k} and ${m} and ${n}`) 
  return takelongtime(k + m + n)
}

async function doIt() {
  console.time("doIt")
  // let time1 = 300;
  // const time2 = await step1(time1)
  // const time3 = await step2(time1, time2)
  // const result = await step3(time1, time2, time3)
  // console.log(`result is ${result}`)
  // console.timeEnd("doIt")
  var p1 = 300,
  p2, p3;
  step1(p1)
    .then((param) => step2(p1, p2 = param))
    .then((param) => step3(p1, p2, p3 = param))
    .then((param) => {
    console.log("result is", param);
    console.timeEnd("doIt")
  })
}
doIt();








































console 命令行工具 X clear

                    
>
console