javascript - Any way to exports a generator function? -
javascript - Any way to exports a generator function? -
an example
generator.js
:
exports.read = function *(){ var = yield read('co.github.js'); var b = yield read('co.recevier.js'); var c = yield read('co.yield.js'); console.log([a,b,c]); } function read(file) { homecoming function(fn){ fs.readfile(file, 'utf8', fn); } }
co.js
:
var co = require('co'); var fs = require('fs'); var gen = require('./generator') /*function read(file) { homecoming function(fn){ fs.readfile(file, 'utf8', fn); } }*/ co(gen.read)()
it seems exports
doesn't back upwards generator function.
require, module, __filename, __dirname) { module.exports.read = function *(){ ^ syntaxerror: unexpected token * @ exports.runinthiscontext (vm.js:69:16) @ module._compile (module.js:432:25) @ object.module._extensions..js (module.js:467:10) @ module.load (module.js:349:32) @ function.module._load (module.js:305:12) @ function.module.runmain (module.js:490:10) @ startup (node.js:123:16) @ node.js:1027:3
why want this? want separate info controllers. way solve it?
you can export whatever want, please not export generator functions in public modules. generators command flow hacks. instead, homecoming promises co@4
exports.fn = co.wrap(function* () { homecoming yield something() }
javascript generator koa co
Comments
Post a Comment