@@ -25,7 +25,9 @@ import { firstToUpperCase, firstToLowerCase } from '../common/utils';
2525import { Port } from './cli-protocol/cc/arduino/cli/commands/v1/port_pb' ;
2626import { nls } from '@theia/core' ;
2727import { MonitorManager } from './monitor-manager' ;
28+ import { SimpleBuffer } from './utils/simple-buffer' ;
2829
30+ const FLUSH_OUTPUT_MESSAGES_TIMEOUT_MS = 32 ;
2931@injectable ( )
3032export class CoreServiceImpl extends CoreClientAware implements CoreService {
3133 @inject ( ResponseService )
@@ -73,18 +75,25 @@ export class CoreServiceImpl extends CoreClientAware implements CoreService {
7375 this . mergeSourceOverrides ( compileReq , options ) ;
7476
7577 const result = client . compile ( compileReq ) ;
78+
79+ const compileBuffer = new SimpleBuffer (
80+ this . flushOutputPanelMessages . bind ( this ) ,
81+ FLUSH_OUTPUT_MESSAGES_TIMEOUT_MS
82+ ) ;
7683 try {
7784 await new Promise < void > ( ( resolve , reject ) => {
7885 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 ( ) ;
8596 } ) ;
86- result . on ( 'error' , ( error ) => reject ( error ) ) ;
87- result . on ( 'end' , ( ) => resolve ( ) ) ;
8897 } ) ;
8998 this . responseService . appendToOutput ( {
9099 chunk : '\n--------------------------\nCompilation complete.\n' ,
@@ -174,18 +183,24 @@ export class CoreServiceImpl extends CoreClientAware implements CoreService {
174183
175184 const result = responseHandler ( client , req ) ;
176185
186+ const uploadBuffer = new SimpleBuffer (
187+ this . flushOutputPanelMessages . bind ( this ) ,
188+ FLUSH_OUTPUT_MESSAGES_TIMEOUT_MS
189+ ) ;
177190 try {
178191 await new Promise < void > ( ( resolve , reject ) => {
179192 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 ( ) ;
186203 } ) ;
187- result . on ( 'error' , ( error ) => reject ( error ) ) ;
188- result . on ( 'end' , ( ) => resolve ( ) ) ;
189204 } ) ;
190205 this . responseService . appendToOutput ( {
191206 chunk :
@@ -238,18 +253,25 @@ export class CoreServiceImpl extends CoreClientAware implements CoreService {
238253 burnReq . setVerify ( options . verify ) ;
239254 burnReq . setVerbose ( options . verbose ) ;
240255 const result = client . burnBootloader ( burnReq ) ;
256+
257+ const bootloaderBuffer = new SimpleBuffer (
258+ this . flushOutputPanelMessages . bind ( this ) ,
259+ FLUSH_OUTPUT_MESSAGES_TIMEOUT_MS
260+ ) ;
241261 try {
242262 await new Promise < void > ( ( resolve , reject ) => {
243263 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 ( ) ;
250274 } ) ;
251- result . on ( 'error' , ( error ) => reject ( error ) ) ;
252- result . on ( 'end' , ( ) => resolve ( ) ) ;
253275 } ) ;
254276 } catch ( e ) {
255277 const errorMessage = nls . localize (
@@ -281,4 +303,10 @@ export class CoreServiceImpl extends CoreClientAware implements CoreService {
281303 }
282304 }
283305 }
306+
307+ private flushOutputPanelMessages ( chunk : string ) : void {
308+ this . responseService . appendToOutput ( {
309+ chunk,
310+ } ) ;
311+ }
284312}
0 commit comments