@@ -21,7 +21,14 @@ class SerialPort {
2121 } catch ( error ) {
2222 console . error ( 'Error disconnecting previous port:' , error ) ;
2323 }
24- await this . _readLoopPromise ;
24+
25+ if ( this . _readLoopPromise ) {
26+ try {
27+ await this . _readLoopPromise ;
28+ } catch ( error ) {
29+ console . error ( 'Error in read loop:' , error ) ;
30+ }
31+ }
2532 this . _readLoopPromise = null ;
2633 }
2734 this . _initialized = true ;
@@ -95,7 +102,13 @@ class SerialPort {
95102 console . error ( 'Error closing port:' , error ) ;
96103 }
97104
98- await this . _readLoopPromise ;
105+ if ( this . _readLoopPromise ) {
106+ try {
107+ await this . _readLoopPromise ;
108+ } catch ( error ) {
109+ console . error ( 'Error in read loop:' , error ) ;
110+ }
111+ }
99112 }
100113
101114 /// Send data to port
@@ -138,7 +151,14 @@ class WebUsbSerialPort {
138151 } catch ( error ) {
139152 console . error ( 'Error disconnecting previous device:' , error ) ;
140153 }
141- await this . _readLoopPromise ;
154+
155+ if ( this . _readLoopPromise ) {
156+ try {
157+ await this . _readLoopPromise ;
158+ } catch ( error ) {
159+ console . error ( 'Error in read loop:' , error ) ;
160+ }
161+ }
142162 this . _readLoopPromise = null ;
143163 }
144164 this . _initialized = true ;
@@ -228,7 +248,13 @@ class WebUsbSerialPort {
228248
229249 await this . _device . releaseInterface ( this . _interfaceNumber ) ;
230250
231- await this . _readLoopPromise ;
251+ if ( this . _readLoopPromise ) {
252+ try {
253+ await this . _readLoopPromise ;
254+ } catch ( error ) {
255+ console . error ( 'Error in read loop:' , error ) ;
256+ }
257+ }
232258 }
233259
234260 /// Send data to device
0 commit comments