From 9d74759f907372817d0ed56fc124e1f7317c9c6f Mon Sep 17 00:00:00 2001 From: Raymond Feng Date: Fri, 31 May 2013 13:10:09 -0700 Subject: [PATCH] Improve connect/disconnect --- lib/datasource.js | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/lib/datasource.js b/lib/datasource.js index 927254c1..b4e31ca9 100644 --- a/lib/datasource.js +++ b/lib/datasource.js @@ -752,11 +752,16 @@ DataSource.prototype.defineForeignKey = function defineForeignKey(className, key * Close database connection */ DataSource.prototype.disconnect = function disconnect(cb) { - if (typeof this.adapter.disconnect === 'function') { - this.connected = false; - this.adapter.disconnect(cb); - } else if (cb) { - cb(); + var self = this; + if (this.connected && (typeof this.adapter.disconnect === 'function')) { + this.adapter.disconnect(function(err, result) { + self.connected = false; + cb && cb(err, result); + }); + } else { + process.nextTick(function() { + cb && cb(); + }); } };