This repository was archived by the owner on Oct 1, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +9
-3
lines changed Expand file tree Collapse file tree 1 file changed +9
-3
lines changed Original file line number Diff line number Diff line change 2
2
// Licensed under the MIT license.
3
3
4
4
import * as vscode from "vscode" ;
5
+ import { performance } from "perf_hooks" ;
5
6
6
7
export class BufferedOutputChannel implements vscode . Disposable {
7
8
private TIMING_BUFFER : number = 300 ;
8
9
9
10
private _buffer : string [ ] ;
10
11
private timer : NodeJS . Timer ;
12
+ private _lastFlushTime : number ;
11
13
12
14
public constructor ( private outputCallback : ( value : string ) => void ) {
13
15
this . _buffer = [ ] ;
14
- this . timer = setInterval ( ( ) => this . flush ( ) , this . TIMING_BUFFER ) ;
16
+ this . timer = setInterval ( ( ) => this . tryFlush ( ) , this . TIMING_BUFFER ) ;
17
+ this . _lastFlushTime = Number . NEGATIVE_INFINITY ;
15
18
}
16
19
17
20
private add ( value : string ) {
18
21
this . _buffer . push ( value ) ;
22
+ this . tryFlush ( ) ;
19
23
}
20
24
21
- private flush ( ) {
22
- if ( this . _buffer && this . _buffer . length > 0 ) {
25
+ private tryFlush ( ) {
26
+ const currentTime = performance . now ( ) ;
27
+ if ( this . _buffer && this . _buffer . length > 0 && currentTime - this . _lastFlushTime > this . TIMING_BUFFER ) {
23
28
this . outputCallback ( this . _buffer . join ( '' ) ) ;
29
+ this . _lastFlushTime = currentTime ;
24
30
this . _buffer = [ ] ;
25
31
}
26
32
}
You can’t perform that action at this time.
0 commit comments