File tree 1 file changed +5
-13
lines changed 1 file changed +5
-13
lines changed Original file line number Diff line number Diff line change @@ -47,27 +47,19 @@ PG.prototype.connect = function(config, callback) {
47
47
name : poolName ,
48
48
create : function ( callback ) {
49
49
var client = new self . Client ( c ) ;
50
- client . connect ( ) ;
51
-
52
- var connectError = function ( err ) {
53
- client . removeListener ( 'connect' , connectSuccess ) ;
54
- callback ( err , null ) ;
55
- } ;
56
-
57
- var connectSuccess = function ( ) {
58
- client . removeListener ( 'error' , connectError ) ;
59
-
50
+ client . connect ( function ( err ) {
51
+ if ( err ) return callback ( err ) ;
52
+
60
53
//handle connected client background errors by emitting event
61
54
//via the pg object and then removing errored client from the pool
62
55
client . on ( 'error' , function ( e ) {
63
56
self . emit ( 'error' , e , client ) ;
64
57
pool . destroy ( client ) ;
65
58
} ) ;
59
+
66
60
callback ( null , client ) ;
67
- } ;
61
+ } ) ;
68
62
69
- client . once ( 'connect' , connectSuccess ) ;
70
- client . once ( 'error' , connectError ) ;
71
63
client . on ( 'drain' , function ( ) {
72
64
pool . release ( client ) ;
73
65
} ) ;
You can’t perform that action at this time.
0 commit comments