1
假设这个简单的模块:异步函数结果模块初始化
var mongoose = require('mongoose-util');
mongoose.myOwnCreateConnection(function(err, connection) {
if(err) {
console.log('log error somehow and make it die');
module.exports = null;
} else {
module.exports = connection;
}
});
它不会明显地工作,但如何管理上下文模块初始化调用?这里最好的做法是什么?我是否需要仅在模块init中使用函数声明?提前致谢。我问,因为快递有应用程序模块,一切都初始化。
猫鼬'createConnection'并不需要一个函数作为它的参数:http://mongoosejs.com/docs/api.html#index_Mongoose-createConnection – krl
这是不明确你在这里试图达到什么 – krl
对不起,这是一个简化,我会编辑这个荒谬的疯狂的例子:) –