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);
28
28
29
29
var p = Client . prototype ;
30
30
31
- p . connect = function ( ) {
31
+ p . connect = function ( callback ) {
32
32
var self = this ;
33
33
var con = this . connection ;
34
34
if ( this . host && this . host . indexOf ( '/' ) === 0 ) {
@@ -84,11 +84,17 @@ p.connect = function() {
84
84
}
85
85
} ) ;
86
86
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
+ }
88
94
89
95
con . on ( 'notification' , function ( msg ) {
90
96
self . emit ( 'notification' , msg ) ;
91
- } )
97
+ } ) ;
92
98
93
99
} ) ;
94
100
@@ -103,7 +109,11 @@ p.connect = function() {
103
109
104
110
con . on ( 'error' , function ( error ) {
105
111
if ( ! self . activeQuery ) {
106
- self . emit ( 'error' , error ) ;
112
+ if ( ! callback ) {
113
+ self . emit ( 'error' , error ) ;
114
+ } else {
115
+ callback ( error ) ;
116
+ }
107
117
} else {
108
118
//need to sync after error during a prepared statement
109
119
if ( self . activeQuery . isPreparedStatement ) {
@@ -116,7 +126,7 @@ p.connect = function() {
116
126
117
127
con . on ( 'notice' , function ( msg ) {
118
128
self . emit ( 'notice' , msg ) ;
119
- } )
129
+ } ) ;
120
130
121
131
} ;
122
132
You can’t perform that action at this time.
0 commit comments