File tree Expand file tree Collapse file tree 1 file changed +15
-5
lines changed
Expand file tree Collapse file tree 1 file changed +15
-5
lines changed Original file line number Diff line number Diff line change @@ -28,7 +28,7 @@ sys.inherits(Client, EventEmitter);
2828
2929var p = Client . prototype ;
3030
31- p . connect = function ( ) {
31+ p . connect = function ( callback ) {
3232 var self = this ;
3333 var con = this . connection ;
3434 if ( this . host && this . host . indexOf ( '/' ) === 0 ) {
@@ -84,11 +84,17 @@ p.connect = function() {
8484 }
8585 } ) ;
8686
87- self . emit ( 'connect' ) ;
87+ if ( ! callback ) {
88+ self . emit ( 'connect' ) ;
89+ } else {
90+ callback ( null , self ) ;
91+ //remove callback for proper error handling after the connect event
92+ callback = null ;
93+ }
8894
8995 con . on ( 'notification' , function ( msg ) {
9096 self . emit ( 'notification' , msg ) ;
91- } )
97+ } ) ;
9298
9399 } ) ;
94100
@@ -103,7 +109,11 @@ p.connect = function() {
103109
104110 con . on ( 'error' , function ( error ) {
105111 if ( ! self . activeQuery ) {
106- self . emit ( 'error' , error ) ;
112+ if ( ! callback ) {
113+ self . emit ( 'error' , error ) ;
114+ } else {
115+ callback ( error ) ;
116+ }
107117 } else {
108118 //need to sync after error during a prepared statement
109119 if ( self . activeQuery . isPreparedStatement ) {
@@ -116,7 +126,7 @@ p.connect = function() {
116126
117127 con . on ( 'notice' , function ( msg ) {
118128 self . emit ( 'notice' , msg ) ;
119- } )
129+ } ) ;
120130
121131} ;
122132
You can’t perform that action at this time.
0 commit comments