////////////decorator//////////
function aopFunc (target, key, descriptor) {
  console.log('aopFunc')
}

class foo {

  @aopFunc
  bar () {
    console.log('fooo')
  }

}
/////////////////////////////

///////////generator///////////
function* asyncFunc () {
  var index = 0;
  while (index < 3) {
    yield index++
  }
}

var func = asyncFunc()
var result
while(result = func.next(), !result.done) {
  console.log(result.value)
}
////////////////////////////////

/////////async/await/////////////
async function sleep(ms) {
  return new Promise((resolve) => {
    setTimeout(resolve, ms)
  })
}

(async function() {
  console.log('Do some thing, ' + new Date())
  await sleep(3000)
  console.log('Do other things, ' + new Date())
})()
//////////////////////////////


//////////async/await////////////
function timeout(ms) {
  return new Promise((resolve) => {
    setTimeout(resolve, ms);
  });
}

async function asyncPrint(value, ms) {
  console.log('before hello world')
  await timeout(ms);
  console.log(value)
  console.log('after hello world')
}
asyncPrint('hello world', 3000)
//////////////////////////////

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-06-29
  • 2022-02-02
  • 2021-07-10
猜你喜欢
  • 2022-12-23
  • 2021-09-11
  • 2022-12-23
  • 2021-06-13
  • 2021-11-30
  • 2022-12-23
  • 2021-10-31
相关资源
相似解决方案