Skip to content
This repository was archived by the owner on Oct 1, 2024. It is now read-only.

Commit cecd379

Browse files
add dispose calls
1 parent f37774f commit cecd379

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

src/serialmonitor/outputBuffer.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,13 @@ import * as vscode from "vscode";
55
import { performance } from "perf_hooks";
66

77
export class BufferedOutputChannel implements vscode.Disposable {
8-
private TIMING_BUFFER: number = 300;
9-
108
private _buffer: string[];
119
private timer: NodeJS.Timer;
1210
private _lastFlushTime: number;
1311

14-
public constructor(private outputCallback: (value: string) => void) {
12+
public constructor(private outputCallback: (value: string) => void, private flushIntervalMs: number) {
1513
this._buffer = [];
16-
this.timer = setInterval(() => this.tryFlush(), this.TIMING_BUFFER);
14+
this.timer = setInterval(() => this.tryFlush(), this.flushIntervalMs);
1715
this._lastFlushTime = Number.NEGATIVE_INFINITY;
1816
}
1917

@@ -24,7 +22,7 @@ export class BufferedOutputChannel implements vscode.Disposable {
2422

2523
private tryFlush() {
2624
const currentTime = performance.now();
27-
if (this._buffer && this._buffer.length > 0 && currentTime-this._lastFlushTime > this.TIMING_BUFFER) {
25+
if (this._buffer.length > 0 && currentTime-this._lastFlushTime > this.flushIntervalMs) {
2826
this.outputCallback(this._buffer.join(''));
2927
this._lastFlushTime = currentTime;
3028
this._buffer = [];

src/serialmonitor/serialMonitor.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ export class SerialMonitor implements vscode.Disposable {
6060
defaultBaudRate = SerialMonitor.DEFAULT_BAUD_RATE;
6161
}
6262
this._outputChannel = vscode.window.createOutputChannel(SerialMonitor.SERIAL_MONITOR);
63-
this._bufferedOutputChannel = new BufferedOutputChannel(this._outputChannel.append);
63+
this._bufferedOutputChannel = new BufferedOutputChannel(this._outputChannel.append, 300);
6464
this._currentBaudRate = defaultBaudRate;
6565
this._portsStatusBar = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Right, constants.statusBarPriority.PORT);
6666
this._portsStatusBar.command = "arduino.selectSerialPort";
@@ -85,13 +85,15 @@ export class SerialMonitor implements vscode.Disposable {
8585
});
8686
}
8787
public get initialized(): boolean {
88-
return !!this._bufferedOutputChannel;
88+
return !!this._outputChannel;
8989
}
9090

9191
public dispose() {
9292
if (this._serialPortCtrl && this._serialPortCtrl.isActive) {
9393
return this._serialPortCtrl.stop();
9494
}
95+
this._outputChannel.dispose();
96+
this._bufferedOutputChannel.dispose();
9597
}
9698

9799
public async selectSerialPort(vid: string, pid: string) {

0 commit comments

Comments
 (0)