File tree Expand file tree Collapse file tree 1 file changed +8
-0
lines changed Expand file tree Collapse file tree 1 file changed +8
-0
lines changed Original file line number Diff line number Diff line change @@ -20,6 +20,7 @@ class WebSerial extends EventTarget {
2020 this . connected = false ;
2121 this . openRequested = false ;
2222 this . openCanceled = false ;
23+ this . closeRequested = false ;
2324 this . transmitting = false ;
2425 this . connectionInfo = null ;
2526
@@ -66,6 +67,7 @@ class WebSerial extends EventTarget {
6667
6768 handleDisconnect ( ) {
6869 this . disconnect ( ) ;
70+ this . closeRequested = true ;
6971 }
7072
7173 getConnectedPort ( ) {
@@ -116,6 +118,7 @@ class WebSerial extends EventTarget {
116118
117119 async connect ( path , options ) {
118120 this . openRequested = true ;
121+ this . closeRequested = false ;
119122
120123 this . port = this . ports . find ( device => device . path === path ) . port ;
121124
@@ -191,6 +194,11 @@ class WebSerial extends EventTarget {
191194 this . bytesReceived = 0 ;
192195 this . bytesSent = 0 ;
193196
197+ // if we are already closing, don't do it again
198+ if ( this . closeRequested ) {
199+ return ;
200+ }
201+
194202 const doCleanup = async ( ) => {
195203 this . removeEventListener ( 'receive' , this . handleReceiveBytes ) ;
196204 if ( this . reader ) {
You can’t perform that action at this time.
0 commit comments