@@ -77,7 +77,8 @@ export class MonitorServiceImpl implements MonitorService {
77
77
config : MonitorConfig ;
78
78
} ;
79
79
protected messages : string [ ] = [ ] ;
80
- protected onMessageReceived : Disposable ;
80
+ protected onMessageReceived : Disposable | null ;
81
+ protected flushMessagesInterval : NodeJS . Timeout | null ;
81
82
82
83
setClient ( client : MonitorServiceClient | undefined ) : void {
83
84
this . client = client ;
@@ -180,7 +181,7 @@ export class MonitorServiceImpl implements MonitorService {
180
181
) ;
181
182
182
183
// empty the queue every 32ms (~30fps)
183
- setInterval ( flushMessagesToFrontend , 32 ) ;
184
+ this . flushMessagesInterval = setInterval ( flushMessagesToFrontend , 32 ) ;
184
185
185
186
// converts 'ab\nc\nd' => [ab\n,c\n,d]
186
187
const stringToArray = ( string : string , separator = '\n' ) => {
@@ -247,7 +248,15 @@ export class MonitorServiceImpl implements MonitorService {
247
248
248
249
async disconnect ( reason ?: MonitorError ) : Promise < Status > {
249
250
try {
250
- this . onMessageReceived . dispose ( ) ;
251
+ if ( this . onMessageReceived ) {
252
+ this . onMessageReceived . dispose ( ) ;
253
+ this . onMessageReceived = null ;
254
+ }
255
+ if ( this . flushMessagesInterval ) {
256
+ clearInterval ( this . flushMessagesInterval ) ;
257
+ this . flushMessagesInterval = null ;
258
+ }
259
+
251
260
if (
252
261
! this . serialConnection &&
253
262
reason &&
0 commit comments