Skip to content

Commit 7a79525

Browse files
dkarpmanjohnfn
authored andcommitted
Update index.js
1 parent a84cf05 commit 7a79525

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

lib/index.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ var PG = function(clientConstructor) {
1313
this.pools = pool;
1414
this.Connection = Connection;
1515
this.types = require('pg-types');
16+
this.num_connections = 0;
17+
this.max_connections = this.defaults.max_connections;
1618
};
1719

1820
util.inherits(PG, EventEmitter);
@@ -39,28 +41,26 @@ PG.prototype.end = function() {
3941
}
4042
};
4143

42-
4344
PG.prototype.connect = function(config, callback) {
4445
if(typeof config == "function") {
4546
callback = config;
4647
config = null;
4748
}
49+
if(this.max_connections && this.num_connections >= this.max_connections) {
50+
return callback && callback(Error("Connection limit", this.max_connections, "reached"));
51+
}
4852
var client = new this.Client(config);
53+
// Max connections waiting to connect
54+
this.num_connections++;
4955
client.connect(function(err) {
56+
this.num_connections--;
5057
if(err) {
5158
return callback && callback(err);
5259
}
5360
return callback && callback(null, client, function() {
5461
client.end();
5562
});
56-
// client.query()
5763
});
58-
/* var pool = this.pools.getOrCreate(config);
59-
pool.connect(callback);
60-
if(!pool.listeners('error').length) {
61-
//propagate errors up to pg object
62-
pool.on('error', this.emit.bind(this, 'error'));
63-
} */
6464
};
6565

6666
// cancel the query runned by the given client

0 commit comments

Comments
 (0)