mirror of
https://github.com/arduino/arduino-ide.git
synced 2025-07-13 14:26:37 +00:00
parent
d6f4096cd0
commit
4611381a38
@ -4,24 +4,25 @@ import { OutputMessage } from '../../common/protocol';
|
|||||||
const DEFAULT_FLUS_TIMEOUT_MS = 32;
|
const DEFAULT_FLUS_TIMEOUT_MS = 32;
|
||||||
|
|
||||||
export class SimpleBuffer implements Disposable {
|
export class SimpleBuffer implements Disposable {
|
||||||
private readonly flush: () => void;
|
|
||||||
private readonly chunks = Chunks.create();
|
private readonly chunks = Chunks.create();
|
||||||
|
private readonly flush: () => void;
|
||||||
private flushInterval?: NodeJS.Timeout;
|
private flushInterval?: NodeJS.Timeout;
|
||||||
|
|
||||||
constructor(onFlush: (chunk: string) => void, flushTimeout: number) {
|
constructor(
|
||||||
const flush = () => {
|
onFlush: (chunks: Map<OutputMessage.Severity, string | undefined>) => void,
|
||||||
if (this.chunks.length > 0) {
|
flushTimeout: number = DEFAULT_FLUS_TIMEOUT_MS
|
||||||
const chunkString = Buffer.concat(this.chunks).toString();
|
) {
|
||||||
|
this.flush = () => {
|
||||||
|
if (!Chunks.isEmpty(this.chunks)) {
|
||||||
|
const chunks = Chunks.toString(this.chunks);
|
||||||
this.clearChunks();
|
this.clearChunks();
|
||||||
onFlush(chunks);
|
onFlush(chunks);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
this.flushInterval = setInterval(this.flush, flushTimeout);
|
||||||
this.flush = flush;
|
|
||||||
this.flushInterval = setInterval(flush, flushTimeout);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public addChunk(
|
addChunk(
|
||||||
chunk: Uint8Array,
|
chunk: Uint8Array,
|
||||||
severity: OutputMessage.Severity = OutputMessage.Severity.Info
|
severity: OutputMessage.Severity = OutputMessage.Severity.Info
|
||||||
): void {
|
): void {
|
||||||
@ -32,10 +33,8 @@ export class SimpleBuffer implements Disposable {
|
|||||||
Chunks.clear(this.chunks);
|
Chunks.clear(this.chunks);
|
||||||
}
|
}
|
||||||
|
|
||||||
public clearFlushInterval(): void {
|
dispose(): void {
|
||||||
this.flush();
|
this.flush();
|
||||||
this.clearChunks();
|
|
||||||
|
|
||||||
clearInterval(this.flushInterval);
|
clearInterval(this.flushInterval);
|
||||||
this.clearChunks();
|
this.clearChunks();
|
||||||
this.flushInterval = undefined;
|
this.flushInterval = undefined;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user