@@ -2,7 +2,6 @@ import { ClientDuplexStream } from '@grpc/grpc-js';
2
2
import { TextEncoder } from 'util' ;
3
3
import { injectable , inject , named } from 'inversify' ;
4
4
import { Struct } from 'google-protobuf/google/protobuf/struct_pb' ;
5
- import { Emitter } from '@theia/core/lib/common/event' ;
6
5
import { ILogger } from '@theia/core/lib/common/logger' ;
7
6
import {
8
7
MonitorService ,
@@ -20,6 +19,7 @@ import { MonitorClientProvider } from './monitor-client-provider';
20
19
import { Board , Port } from '../../common/protocol/boards-service' ;
21
20
import { WebSocketService } from '../web-socket/web-socket-service' ;
22
21
import { SerialPlotter } from '../../browser/plotter/protocol' ;
22
+ import { Disposable } from '@theia/core/shared/vscode-languageserver-protocol' ;
23
23
24
24
interface ErrorWithCode extends Error {
25
25
readonly code : number ;
@@ -77,7 +77,7 @@ export class MonitorServiceImpl implements MonitorService {
77
77
config : MonitorConfig ;
78
78
} ;
79
79
protected messages : string [ ] = [ ] ;
80
- protected onMessageDidReadEmitter = new Emitter < void > ( ) ;
80
+ protected onMessageReceived : Disposable ;
81
81
82
82
setClient ( client : MonitorServiceClient | undefined ) : void {
83
83
this . client = client ;
@@ -148,34 +148,36 @@ export class MonitorServiceImpl implements MonitorService {
148
148
}
149
149
} ;
150
150
151
- this . webSocketService . onMessageReceived ( ( msg : string ) => {
152
- try {
153
- const message : SerialPlotter . Protocol . Message = JSON . parse ( msg ) ;
151
+ this . onMessageReceived = this . webSocketService . onMessageReceived (
152
+ ( msg : string ) => {
153
+ try {
154
+ const message : SerialPlotter . Protocol . Message = JSON . parse ( msg ) ;
154
155
155
- switch ( message . command ) {
156
- case SerialPlotter . Protocol . Command . PLOTTER_SEND_MESSAGE :
157
- this . sendMessageToSerial ( message . data ) ;
158
- break ;
156
+ switch ( message . command ) {
157
+ case SerialPlotter . Protocol . Command . PLOTTER_SEND_MESSAGE :
158
+ this . sendMessageToSerial ( message . data ) ;
159
+ break ;
159
160
160
- case SerialPlotter . Protocol . Command . PLOTTER_SET_BAUDRATE :
161
- this . client ?. notifyBaudRateChanged (
162
- parseInt ( message . data , 10 ) as MonitorConfig . BaudRate
163
- ) ;
164
- break ;
161
+ case SerialPlotter . Protocol . Command . PLOTTER_SET_BAUDRATE :
162
+ this . client ?. notifyBaudRateChanged (
163
+ parseInt ( message . data , 10 ) as MonitorConfig . BaudRate
164
+ ) ;
165
+ break ;
165
166
166
- case SerialPlotter . Protocol . Command . PLOTTER_SET_LINE_ENDING :
167
- this . client ?. notifyLineEndingChanged ( message . data ) ;
168
- break ;
167
+ case SerialPlotter . Protocol . Command . PLOTTER_SET_LINE_ENDING :
168
+ this . client ?. notifyLineEndingChanged ( message . data ) ;
169
+ break ;
169
170
170
- case SerialPlotter . Protocol . Command . PLOTTER_SET_INTERPOLATE :
171
- this . client ?. notifyInterpolateChanged ( message . data ) ;
172
- break ;
171
+ case SerialPlotter . Protocol . Command . PLOTTER_SET_INTERPOLATE :
172
+ this . client ?. notifyInterpolateChanged ( message . data ) ;
173
+ break ;
173
174
174
- default :
175
- break ;
176
- }
177
- } catch ( error ) { }
178
- } ) ;
175
+ default :
176
+ break ;
177
+ }
178
+ } catch ( error ) { }
179
+ }
180
+ ) ;
179
181
180
182
// empty the queue every 32ms (~30fps)
181
183
setInterval ( flushMessagesToFrontend , 32 ) ;
@@ -245,6 +247,7 @@ export class MonitorServiceImpl implements MonitorService {
245
247
246
248
async disconnect ( reason ?: MonitorError ) : Promise < Status > {
247
249
try {
250
+ this . onMessageReceived . dispose ( ) ;
248
251
if (
249
252
! this . serialConnection &&
250
253
reason &&
0 commit comments