Skip to content

Commit 4a5c000

Browse files
committed
Merge pull request #507 from 140proof/master
Make sure pool requests always behave asynchronously
2 parents fc661dc + d575adc commit 4a5c000

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

lib/Pool.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,19 @@ function Pool(options) {
1919

2020
Pool.prototype.getConnection = function (cb) {
2121
if (this._closed) {
22-
return cb(new Error('Pool is closed.'));
22+
return process.nextTick(function(){
23+
return cb(new Error('Pool is closed.'));
24+
});
2325
}
2426

2527
var connection;
2628

2729
if (this._freeConnections.length > 0) {
2830
connection = this._freeConnections.shift();
2931

30-
return cb(null, connection);
32+
return process.nextTick(function(){
33+
return cb(null, connection);
34+
});
3135
}
3236

3337
if (this.config.connectionLimit === 0 || this._allConnections.length < this.config.connectionLimit) {
@@ -49,7 +53,9 @@ Pool.prototype.getConnection = function (cb) {
4953
}
5054

5155
if (!this.config.waitForConnections) {
52-
return cb(new Error('No connections available.'));
56+
return process.nextTick(function(){
57+
return cb(new Error('No connections available.'));
58+
});
5359
}
5460

5561
if (this.config.queueLimit && this._connectionQueue.length >= this.config.queueLimit) {

0 commit comments

Comments
 (0)