# 异步编程

# Promise

# generator yeild

# async await

const fnAll = async () => {
  console.log('in')
  await fn1()
  fn2()
  await fn3()
  console.log('out')
}
const fn1 = () => {
  return new Promise(resolve => {
    setTimeout(() => {
      console.log('fn1')
      resolve()
    }, 1000);
  })
}
const fn2 = () => {
  setTimeout(() => {
    console.log('fn2')
  }, 500)
}
const fn3 = async () => {
  console.log('fn3')
}

fnAll()

// in fn1 fn3 out fn2
  • 简单函数 只是使用 async 定义有作用吗?

  • await 如何让函数等待执行

  • 异步任务队列按顺序依次执行

  • promise 和 await 搭配使用

  • yeild generator

  • 手写promise