Skip to content

Commit 4611381

Browse files
Akos Kittakittaakos
Akos Kitta
authored andcommitted
Merged in #1074.
Signed-off-by: Akos Kitta <[email protected]>
1 parent d6f4096 commit 4611381

File tree

1 file changed

+11
-12
lines changed

1 file changed

+11
-12
lines changed

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

+11-12
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,25 @@ import { OutputMessage } from '../../common/protocol';
44
const DEFAULT_FLUS_TIMEOUT_MS = 32;
55

66
export class SimpleBuffer implements Disposable {
7-
private readonly flush: () => void;
87
private readonly chunks = Chunks.create();
8+
private readonly flush: () => void;
99
private flushInterval?: NodeJS.Timeout;
1010

11-
constructor(onFlush: (chunk: string) => void, flushTimeout: number) {
12-
const flush = () => {
13-
if (this.chunks.length > 0) {
14-
const chunkString = Buffer.concat(this.chunks).toString();
11+
constructor(
12+
onFlush: (chunks: Map<OutputMessage.Severity, string | undefined>) => void,
13+
flushTimeout: number = DEFAULT_FLUS_TIMEOUT_MS
14+
) {
15+
this.flush = () => {
16+
if (!Chunks.isEmpty(this.chunks)) {
17+
const chunks = Chunks.toString(this.chunks);
1518
this.clearChunks();
1619
onFlush(chunks);
1720
}
1821
};
19-
20-
this.flush = flush;
21-
this.flushInterval = setInterval(flush, flushTimeout);
22+
this.flushInterval = setInterval(this.flush, flushTimeout);
2223
}
2324

24-
public addChunk(
25+
addChunk(
2526
chunk: Uint8Array,
2627
severity: OutputMessage.Severity = OutputMessage.Severity.Info
2728
): void {
@@ -32,10 +33,8 @@ export class SimpleBuffer implements Disposable {
3233
Chunks.clear(this.chunks);
3334
}
3435

35-
public clearFlushInterval(): void {
36+
dispose(): void {
3637
this.flush();
37-
this.clearChunks();
38-
3938
clearInterval(this.flushInterval);
4039
this.clearChunks();
4140
this.flushInterval = undefined;

0 commit comments

Comments
 (0)