@@ -25,7 +25,9 @@ import { firstToUpperCase, firstToLowerCase } from '../common/utils';
25
25
import { Port } from './cli-protocol/cc/arduino/cli/commands/v1/port_pb' ;
26
26
import { nls } from '@theia/core' ;
27
27
import { MonitorManager } from './monitor-manager' ;
28
+ import { SimpleBuffer } from './utils/simple-buffer' ;
28
29
30
+ const FLUSH_OUTPUT_MESSAGES_TIMEOUT_MS = 32 ;
29
31
@injectable ( )
30
32
export class CoreServiceImpl extends CoreClientAware implements CoreService {
31
33
@inject ( ResponseService )
@@ -73,18 +75,25 @@ export class CoreServiceImpl extends CoreClientAware implements CoreService {
73
75
this . mergeSourceOverrides ( compileReq , options ) ;
74
76
75
77
const result = client . compile ( compileReq ) ;
78
+
79
+ const compileBuffer = new SimpleBuffer (
80
+ this . flushOutputPanelMessages . bind ( this ) ,
81
+ FLUSH_OUTPUT_MESSAGES_TIMEOUT_MS
82
+ ) ;
76
83
try {
77
84
await new Promise < void > ( ( resolve , reject ) => {
78
85
result . on ( 'data' , ( cr : CompileResponse ) => {
79
- this . responseService . appendToOutput ( {
80
- chunk : Buffer . from ( cr . getOutStream_asU8 ( ) ) . toString ( ) ,
81
- } ) ;
82
- this . responseService . appendToOutput ( {
83
- chunk : Buffer . from ( cr . getErrStream_asU8 ( ) ) . toString ( ) ,
84
- } ) ;
86
+ compileBuffer . addChunk ( cr . getOutStream_asU8 ( ) ) ;
87
+ compileBuffer . addChunk ( cr . getErrStream_asU8 ( ) ) ;
88
+ } ) ;
89
+ result . on ( 'error' , ( error ) => {
90
+ compileBuffer . clearFlushInterval ( ) ;
91
+ reject ( error ) ;
92
+ } ) ;
93
+ result . on ( 'end' , ( ) => {
94
+ compileBuffer . clearFlushInterval ( ) ;
95
+ resolve ( ) ;
85
96
} ) ;
86
- result . on ( 'error' , ( error ) => reject ( error ) ) ;
87
- result . on ( 'end' , ( ) => resolve ( ) ) ;
88
97
} ) ;
89
98
this . responseService . appendToOutput ( {
90
99
chunk : '\n--------------------------\nCompilation complete.\n' ,
@@ -174,18 +183,24 @@ export class CoreServiceImpl extends CoreClientAware implements CoreService {
174
183
175
184
const result = responseHandler ( client , req ) ;
176
185
186
+ const uploadBuffer = new SimpleBuffer (
187
+ this . flushOutputPanelMessages . bind ( this ) ,
188
+ FLUSH_OUTPUT_MESSAGES_TIMEOUT_MS
189
+ ) ;
177
190
try {
178
191
await new Promise < void > ( ( resolve , reject ) => {
179
192
result . on ( 'data' , ( resp : UploadResponse ) => {
180
- this . responseService . appendToOutput ( {
181
- chunk : Buffer . from ( resp . getOutStream_asU8 ( ) ) . toString ( ) ,
182
- } ) ;
183
- this . responseService . appendToOutput ( {
184
- chunk : Buffer . from ( resp . getErrStream_asU8 ( ) ) . toString ( ) ,
185
- } ) ;
193
+ uploadBuffer . addChunk ( resp . getOutStream_asU8 ( ) ) ;
194
+ uploadBuffer . addChunk ( resp . getErrStream_asU8 ( ) ) ;
195
+ } ) ;
196
+ result . on ( 'error' , ( error ) => {
197
+ uploadBuffer . clearFlushInterval ( ) ;
198
+ reject ( error ) ;
199
+ } ) ;
200
+ result . on ( 'end' , ( ) => {
201
+ uploadBuffer . clearFlushInterval ( ) ;
202
+ resolve ( ) ;
186
203
} ) ;
187
- result . on ( 'error' , ( error ) => reject ( error ) ) ;
188
- result . on ( 'end' , ( ) => resolve ( ) ) ;
189
204
} ) ;
190
205
this . responseService . appendToOutput ( {
191
206
chunk :
@@ -238,18 +253,25 @@ export class CoreServiceImpl extends CoreClientAware implements CoreService {
238
253
burnReq . setVerify ( options . verify ) ;
239
254
burnReq . setVerbose ( options . verbose ) ;
240
255
const result = client . burnBootloader ( burnReq ) ;
256
+
257
+ const bootloaderBuffer = new SimpleBuffer (
258
+ this . flushOutputPanelMessages . bind ( this ) ,
259
+ FLUSH_OUTPUT_MESSAGES_TIMEOUT_MS
260
+ ) ;
241
261
try {
242
262
await new Promise < void > ( ( resolve , reject ) => {
243
263
result . on ( 'data' , ( resp : BurnBootloaderResponse ) => {
244
- this . responseService . appendToOutput ( {
245
- chunk : Buffer . from ( resp . getOutStream_asU8 ( ) ) . toString ( ) ,
246
- } ) ;
247
- this . responseService . appendToOutput ( {
248
- chunk : Buffer . from ( resp . getErrStream_asU8 ( ) ) . toString ( ) ,
249
- } ) ;
264
+ bootloaderBuffer . addChunk ( resp . getOutStream_asU8 ( ) ) ;
265
+ bootloaderBuffer . addChunk ( resp . getErrStream_asU8 ( ) ) ;
266
+ } ) ;
267
+ result . on ( 'error' , ( error ) => {
268
+ bootloaderBuffer . clearFlushInterval ( ) ;
269
+ reject ( error ) ;
270
+ } ) ;
271
+ result . on ( 'end' , ( ) => {
272
+ bootloaderBuffer . clearFlushInterval ( ) ;
273
+ resolve ( ) ;
250
274
} ) ;
251
- result . on ( 'error' , ( error ) => reject ( error ) ) ;
252
- result . on ( 'end' , ( ) => resolve ( ) ) ;
253
275
} ) ;
254
276
} catch ( e ) {
255
277
const errorMessage = nls . localize (
@@ -281,4 +303,10 @@ export class CoreServiceImpl extends CoreClientAware implements CoreService {
281
303
}
282
304
}
283
305
}
306
+
307
+ private flushOutputPanelMessages ( chunk : string ) : void {
308
+ this . responseService . appendToOutput ( {
309
+ chunk,
310
+ } ) ;
311
+ }
284
312
}
0 commit comments