evantianx / Bloooooooog

Place to record what I thought and learned
0 stars 0 forks source link

Tips from video #49

Open evantianx opened 7 years ago

evantianx commented 7 years ago

看视频的总结笔记📒

evantianx commented 7 years ago

The Future Of ES6

ES 特性 Maturity Stages

Cancel Tokens

async function getStockPrice(name, cancelToken) {
  await.cancelToken = cancelToken
  let symbol = await getStockSymbol(name, cancelToken)
  let price = await getSymbolPrice(stmbol, cancelToken)
  return price
}

let { token, cancel } = cancelToken.source()

getStockPrice("Johnson and Johnson", token)
  .then(price => console.log(price))

// 随时终止异步操作
cancel()

Async Generator Functions

async function* getStocks() {
  let reader = new AsyncFileReader('stock.txt')
  try {
    while (!reader.eof) {
      let line = await reader.readline()
      yield JSON.parse(line)
    }
  }
  finally {
    await reader.close()
  }
}

使用示意图: 2017-08-13 8 27 12

evantianx commented 7 years ago

10 Tips For Clean Code