Skip to content

Commit f7e10e1

Browse files
author
Alex Corbi
committed
Implementing #1
1 parent 6ad9f4b commit f7e10e1

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

lib/Pool.js

+44
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,50 @@ Pool.prototype.getConnection = function (cb) {
6969
this._enqueueCallback(cb);
7070
};
7171

72+
Pool.prototype.getNewConnection = function (cb) {
73+
74+
if (this._closed) {
75+
return process.nextTick(function(){
76+
return cb(new Error('Pool is closed.'));
77+
});
78+
}
79+
80+
var connection;
81+
var pool = this;
82+
83+
if (this.config.connectionLimit === 0 || this._allConnections.length < this.config.connectionLimit) {
84+
connection = new PoolConnection(this, { config: this.config.newConnectionConfig() });
85+
86+
this._acquiringConnections.push(connection);
87+
this._allConnections.push(connection);
88+
89+
return connection.connect({timeout: this.config.acquireTimeout}, function onConnect(err) {
90+
spliceConnection(pool._acquiringConnections, connection);
91+
92+
if (pool._closed) {
93+
err = new Error('Pool is closed.');
94+
}
95+
96+
if (err) {
97+
pool._purgeConnection(connection);
98+
cb(err);
99+
return;
100+
}
101+
102+
pool.emit('connection', connection);
103+
cb(null, connection);
104+
});
105+
}
106+
107+
if (!this.config.waitForConnections) {
108+
return process.nextTick(function(){
109+
return cb(new Error('No connections available.'));
110+
});
111+
}
112+
113+
this._enqueueCallback(cb);
114+
};
115+
72116
Pool.prototype.acquireConnection = function acquireConnection(connection, cb) {
73117
if (connection._pool !== this) {
74118
throw new Error('Connection acquired from wrong pool.');

0 commit comments

Comments
 (0)