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) {
var schema = this;
schema.connecting = true;
schema.adapter.connect(function(err) {
if (!err) {
schema.connected = true;
schema.connecting = false;
schema.emit('connected');
}
if (cb) {
cb(err);
}
});
if (schema.adapter.connect) {
schema.adapter.connect(function(err) {
if (!err) {
schema.connected = true;
schema.connecting = false;
schema.emit('connected');
}
if (cb) {
cb(err);
}
});
} else {
process.nextTick(cb);
}
};
};