Skip to content

Commit 57018b9

Browse files
committed
Update index.js
1 parent 78cc738 commit 57018b9

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);
@@ -35,28 +37,26 @@ PG.prototype.end = function() {
3537
});
3638
};
3739

38-
3940
PG.prototype.connect = function(config, callback) {
4041
if(typeof config == "function") {
4142
callback = config;
4243
config = null;
4344
}
45+
if(this.max_connections && this.num_connections >= this.max_connections) {
46+
return callback && callback(Error("Connection limit", this.max_connections, "reached"));
47+
}
4448
var client = new this.Client(config);
49+
// Max connections waiting to connect
50+
this.num_connections++;
4551
client.connect(function(err) {
52+
this.num_connections--;
4653
if(err) {
4754
return callback && callback(err);
4855
}
4956
return callback && callback(null, client, function() {
5057
client.end();
5158
});
52-
// client.query()
5359
});
54-
/* var pool = this.pools.getOrCreate(config);
55-
pool.connect(callback);
56-
if(!pool.listeners('error').length) {
57-
//propagate errors up to pg object
58-
pool.on('error', this.emit.bind(this, 'error'));
59-
} */
6060
};
6161

6262
// cancel the query runned by the given client

0 commit comments

Comments
 (0)