forked from arduino/arduino-ide
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Output panel optimisation (arduino#1058)
* test interval for output panel * create buffer provider * output panel buffer corrections * output buffer cleanup * code cleanup
- Loading branch information
1 parent
a804766
commit 4c62431
Showing
2 changed files
with
83 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
export class SimpleBuffer { | ||
private chunks: Uint8Array[] = []; | ||
|
||
private flushInterval?: NodeJS.Timeout; | ||
|
||
constructor(onFlush: (chunk: string) => void, flushTimeout: number) { | ||
this.flushInterval = setInterval(() => { | ||
if (this.chunks.length > 0) { | ||
const chunkString = Buffer.concat(this.chunks).toString(); | ||
this.clearChunks(); | ||
|
||
onFlush(chunkString); | ||
} | ||
}, flushTimeout); | ||
} | ||
|
||
public addChunk(chunk: Uint8Array): void { | ||
this.chunks.push(chunk); | ||
} | ||
|
||
private clearChunks(): void { | ||
this.chunks = []; | ||
} | ||
|
||
public clearFlushInterval(): void { | ||
this.clearChunks(); | ||
|
||
clearInterval(this.flushInterval); | ||
this.flushInterval = undefined; | ||
} | ||
} |