logo
  • 教程列表
  • SO官方文檔
  • 藍鳥承諾
    • 將 nodeback 庫轉換為 Promises
    • 功能承諾
    • 協同程式(發生器)
    • 自動資源處置(Promise.using)
    • 執行系列
  1. StackOverflow 文件
  2. Node.js 教程
  3. 藍鳥承諾
  4. 協同程式(發生器)

協同程式(發生器)

Created: November-22, 2018

const promiseReturningFunction = Promise.coroutine(function* (file) {
  const data = yield fs.readFileAsync(file) // this returns a Promise and resolves to the file contents

  return data.toString().toUpperCase()
})

promiseReturningFunction('file.txt').then(console.log)
  • 自動資源處置(Promise.using)
  • 功能承諾

Copyright © 2018. All right reserved

tastones.com 备案号:鲁ICP备18045372号-1

  • 關於本站
  • 免責聲明