From 8370538e4e268e0eb698118dacf4fba107280543 Mon Sep 17 00:00:00 2001 From: Anatoliy Chakkaev Date: Mon, 22 Apr 2013 16:22:20 +0400 Subject: [PATCH] Safe connect call --- lib/schema.js | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/lib/schema.js b/lib/schema.js index 2809e173..e65529c7 100644 --- a/lib/schema.js +++ b/lib/schema.js @@ -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); + } }; };