File tree 1 file changed +44
-0
lines changed
1 file changed +44
-0
lines changed Original file line number Diff line number Diff line change @@ -69,6 +69,50 @@ Pool.prototype.getConnection = function (cb) {
69
69
this . _enqueueCallback ( cb ) ;
70
70
} ;
71
71
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
+
72
116
Pool . prototype . acquireConnection = function acquireConnection ( connection , cb ) {
73
117
if ( connection . _pool !== this ) {
74
118
throw new Error ( 'Connection acquired from wrong pool.' ) ;
You can’t perform that action at this time.
0 commit comments