SOURCE

function sleep(time){
  return new Promise((resolve,reject)=>{
     setTimeout(()=>{
       resolve("a")
     },time)
  })
}

async function go(){
  let a = await sleep(1000)
  console.log(a)
}

function run(genFn){
  return new Promise((resolve,reject)=>{
     let interator = genFn();
     step()
     function step(value){
      let result = interator.next(value)
      if(result.done){
        resolve(result.value)
        return 
      }
       Promise.resolve(result.value).then((data)=>{
         step(data)
       })
     }
  })
}

function* goFn(){
  let a = yield sleep(1000)
  return 'done'
}
run(goFn)
console 命令行工具 X clear

                    
>
console