Safe connect call

This commit is contained in:
Anatoliy Chakkaev 2013-04-22 16:22:20 +04:00 committed by Raymond Feng
parent 23004c12c1
commit 8370538e4e
1 changed files with 14 additions and 10 deletions

View File

@ -122,16 +122,20 @@ function Schema(name, settings) {
schema.connect = function(cb) { schema.connect = function(cb) {
var schema = this; var schema = this;
schema.connecting = true; schema.connecting = true;
schema.adapter.connect(function(err) { if (schema.adapter.connect) {
if (!err) { schema.adapter.connect(function(err) {
schema.connected = true; if (!err) {
schema.connecting = false; schema.connected = true;
schema.emit('connected'); schema.connecting = false;
} schema.emit('connected');
if (cb) { }
cb(err); if (cb) {
} cb(err);
}); }
});
} else {
process.nextTick(cb);
}
}; };
}; };