File tree 2 files changed +26
-0
lines changed
2 files changed +26
-0
lines changed Original file line number Diff line number Diff line change @@ -14,6 +14,7 @@ var Pool = module.exports = function (options, Client) {
14
14
this . options . create = this . options . create || this . _create . bind ( this )
15
15
this . options . destroy = this . options . destroy || this . _destroy . bind ( this )
16
16
this . pool = new genericPool . Pool ( this . options )
17
+ this . onCreate = this . options . onCreate
17
18
}
18
19
19
20
util . inherits ( Pool , EventEmitter )
@@ -37,6 +38,7 @@ Pool.prototype._create = function (cb) {
37
38
38
39
client . connect ( function ( err ) {
39
40
this . log ( 'client connected' )
41
+ this . emit ( 'connect' , client )
40
42
if ( err ) {
41
43
this . log ( 'client connection error:' , err )
42
44
cb ( err )
Original file line number Diff line number Diff line change
1
+ var expect = require ( 'expect.js' )
2
+
3
+ var describe = require ( 'mocha' ) . describe
4
+ var it = require ( 'mocha' ) . it
5
+
6
+ var Pool = require ( '../' )
7
+
8
+ describe ( 'events' , function ( ) {
9
+ it ( 'emits connect before callback' , function ( done ) {
10
+ var pool = new Pool ( )
11
+ var emittedClient = false
12
+ pool . on ( 'connect' , function ( client ) {
13
+ emittedClient = client
14
+ } )
15
+
16
+ pool . connect ( function ( err , client , release ) {
17
+ if ( err ) return done ( err )
18
+ release ( )
19
+ pool . end ( )
20
+ expect ( client ) . to . be ( emittedClient )
21
+ done ( )
22
+ } )
23
+ } )
24
+ } )
You can’t perform that action at this time.
0 commit comments