0

我有一个生成器函数,它创建一个目录并在完成后对其执行操作:

import co from 'co'    
import map from 'lodash/fp/map'
import path from 'path'
import {mkdirp} from 'fs-promise'
import co from 'co'


 export const createDirectoryForMake = (parentDir,makeName) => {
  const dirPath = path.join(parentDir,makeName)
  return mkdirp(dirPath)
}


function getGenerateMakeOutput(parentDir,byMake,makeName){
   function * generateMakeOutput() {
    try {
      console.log('before create directory for make')
      const dirStatus = yield createDirectoryForMake(parentDir,makeName)
      } catch(e) {
        console.error(e)
      }
  }

  co(generateMakeOutput)

}

这是我执行代码时得到的输出:

TypeError: You may only yield a function, promise, generator, array, or object, but the following object was passed: "undefined"
    at next (/home/vamsi/Do/redbubble-demo/node_modules/co/index.js:101:25)
    at onFulfilled (/home/vamsi/Do/redbubble-demo/node_modules/co/index.js:69:7)
    at run (/home/vamsi/Do/redbubble-demo/node_modules/core-js/modules/es6.promise.js:89:22)
    at /home/vamsi/Do/redbubble-demo/node_modules/core-js/modules/es6.promise.js:102:28
    at flush (/home/vamsi/Do/redbubble-demo/node_modules/core-js/modules/_microtask.js:18:9)
    at _combinedTickCallback (internal/process/next_tick.js:67:7)
    at process._tickCallback (internal/process/next_tick.js:98:9)

更新:

我发现了这个问题,它与示例中的代码无关,而是在我编写此 gem 的地方有一行:

yield Promise.all[promiseA,promiseB]
4

0 回答 0