@@ -224,16 +224,11 @@ class Serial extends EventTarget {
224
224
225
225
// If we're connected to a different port, disconnect first
226
226
console . log ( `${ this . logHead } Connected to a different port, disconnecting first` ) ;
227
- this . disconnect ( ( success ) => {
228
- if ( success ) {
229
- // Now connect to the new port
230
- console . log ( `${ this . logHead } Reconnecting to new port:` , path ) ;
231
- this . _protocol . connect ( path , options ) ;
232
- } else {
233
- console . error ( `${ this . logHead } Failed to disconnect before reconnecting` ) ;
234
- return false ;
235
- }
236
- } ) ;
227
+ const success = await this . disconnect ( ) ;
228
+ if ( ! success ) {
229
+ console . error ( `${ this . logHead } Failed to disconnect before reconnecting` ) ;
230
+ return false ;
231
+ }
237
232
238
233
console . log ( `${ this . logHead } Reconnecting to new port:` , path ) ;
239
234
return this . _protocol . connect ( path , options ) ;
@@ -269,30 +264,16 @@ class Serial extends EventTarget {
269
264
}
270
265
271
266
// Create a promise that will resolve/reject based on the protocol's disconnect result
272
- return new Promise ( ( resolve ) => {
273
- // Call the protocol's disconnect with a callback that will resolve our promise
274
- this . _protocol . disconnect ( ( success ) => {
275
- if ( success ) {
276
- console . log ( `${ this . logHead } Disconnection successful` ) ;
277
- } else {
278
- console . error ( `${ this . logHead } Disconnection failed` ) ;
279
- }
280
-
281
- // Call original callback
282
- if ( callback ) {
283
- callback ( success ) ;
284
- }
285
-
286
- // Resolve our promise with the success value
287
- resolve ( success ) ;
288
- } ) ;
289
- } ) ;
267
+ const success = await this . _protocol . disconnect ( ) ;
268
+
269
+ if ( callback ) callback ( success ) ;
270
+ return success ;
290
271
} catch ( error ) {
291
272
console . error ( `${ this . logHead } Error during disconnect:` , error ) ;
292
273
if ( callback ) {
293
274
callback ( false ) ;
294
275
}
295
- return false ;
276
+ return Promise . resolve ( false ) ;
296
277
}
297
278
}
298
279
0 commit comments