Skip to content

Commit

Permalink
flush on clear output buffer (arduino#1074)
Browse files Browse the repository at this point in the history
  • Loading branch information
davegarthsimpson authored Jun 20, 2022
1 parent 94ceefd commit a715da3
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions arduino-ide-extension/src/node/utils/simple-buffer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,20 @@ export class SimpleBuffer {

private flushInterval?: NodeJS.Timeout;

private flush: () => void;

constructor(onFlush: (chunk: string) => void, flushTimeout: number) {
this.flushInterval = setInterval(() => {
const flush = () => {
if (this.chunks.length > 0) {
const chunkString = Buffer.concat(this.chunks).toString();
this.clearChunks();

onFlush(chunkString);
}
}, flushTimeout);
};

this.flush = flush;
this.flushInterval = setInterval(flush, flushTimeout);
}

public addChunk(chunk: Uint8Array): void {
Expand All @@ -23,6 +28,7 @@ export class SimpleBuffer {
}

public clearFlushInterval(): void {
this.flush();
this.clearChunks();

clearInterval(this.flushInterval);
Expand Down

0 comments on commit a715da3

Please sign in to comment.