File tree 1 file changed +18
-12
lines changed
1 file changed +18
-12
lines changed Original file line number Diff line number Diff line change @@ -53,16 +53,15 @@ var Client = function (config) {
53
53
54
54
util . inherits ( Client , EventEmitter )
55
55
56
- Client . prototype . connect = function ( callback ) {
56
+ Client . prototype . _connect = function ( callback ) {
57
57
var self = this
58
58
var con = this . connection
59
59
if ( this . _connecting || this . _connected ) {
60
60
const err = new Error ( 'Client has already been connected. You cannot reuse a client.' )
61
- if ( callback ) {
61
+ process . nextTick ( ( ) => {
62
62
callback ( err )
63
- return undefined
64
- }
65
- return Promise . reject ( err )
63
+ } )
64
+ return
66
65
}
67
66
this . _connecting = true
68
67
@@ -220,16 +219,23 @@ Client.prototype.connect = function (callback) {
220
219
con . on ( 'notice' , function ( msg ) {
221
220
self . emit ( 'notice' , msg )
222
221
} )
222
+ }
223
+
224
+ Client . prototype . connect = function ( callback ) {
225
+ if ( callback ) {
226
+ this . _connect ( callback )
227
+ return
228
+ }
223
229
224
- if ( ! callback ) {
225
- return new global . Promise ( ( resolve , reject ) => {
226
- this . once ( ' error' , reject )
227
- this . once ( 'connect' , ( ) => {
228
- this . removeListener ( 'error' , reject )
230
+ return new Promise ( ( resolve , reject ) => {
231
+ this . _connect ( ( error ) => {
232
+ if ( error ) {
233
+ reject ( error )
234
+ } else {
229
235
resolve ( )
230
- } )
236
+ }
231
237
} )
232
- }
238
+ } )
233
239
}
234
240
235
241
Client . prototype . _attachListeners = function ( con ) {
You can’t perform that action at this time.
0 commit comments