@@ -2,6 +2,18 @@ var core = require('./index.js');
2
2
var EventEmitter = require ( 'events' ) . EventEmitter ;
3
3
var util = require ( 'util' ) ;
4
4
5
+ function inheritEvents ( source , target , events ) {
6
+ events
7
+ . forEach ( function ( eventName ) {
8
+ source . on ( eventName , function ( ) {
9
+ var args = [ ] . slice . call ( arguments ) ;
10
+ args . unshift ( eventName ) ;
11
+
12
+ target . emit . apply ( target , args ) ;
13
+ } ) ;
14
+ } ) ;
15
+ }
16
+
5
17
function createConnection ( opts ) {
6
18
var coreConnection = core . createConnection ( opts ) ;
7
19
var Promise = opts . Promise || global . Promise ;
@@ -171,17 +183,7 @@ function PromisePool(pool, Promise) {
171
183
this . pool = pool ;
172
184
this . Promise = Promise ;
173
185
174
- [ 'acquire' , 'connection' , 'enqueue' , 'release' ]
175
- . forEach ( function ( eventName ) {
176
- var t = this ;
177
-
178
- this . pool . on ( eventName , function ( ) {
179
- var args = [ ] . slice . call ( arguments ) ;
180
- args . unshift ( eventName ) ;
181
-
182
- t . emit . apply ( t , args ) ;
183
- } ) ;
184
- } , this ) ;
186
+ inheritEvents ( pool , this , [ 'acquire' , 'connection' , 'enqueue' , 'release' ] ) ;
185
187
}
186
188
util . inherits ( PromisePool , EventEmitter ) ;
187
189
0 commit comments