Skip to content

Commit a715da3

Browse files
flush on clear output buffer (#1074)
1 parent 94ceefd commit a715da3

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

arduino-ide-extension/src/node/utils/simple-buffer.ts

+8-2
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,20 @@ export class SimpleBuffer {
33

44
private flushInterval?: NodeJS.Timeout;
55

6+
private flush: () => void;
7+
68
constructor(onFlush: (chunk: string) => void, flushTimeout: number) {
7-
this.flushInterval = setInterval(() => {
9+
const flush = () => {
810
if (this.chunks.length > 0) {
911
const chunkString = Buffer.concat(this.chunks).toString();
1012
this.clearChunks();
1113

1214
onFlush(chunkString);
1315
}
14-
}, flushTimeout);
16+
};
17+
18+
this.flush = flush;
19+
this.flushInterval = setInterval(flush, flushTimeout);
1520
}
1621

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

2530
public clearFlushInterval(): void {
31+
this.flush();
2632
this.clearChunks();
2733

2834
clearInterval(this.flushInterval);

0 commit comments

Comments
 (0)