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

  • 关于我们
  • 免责声明