@@ -4,24 +4,25 @@ import { OutputMessage } from '../../common/protocol';
4
4
const DEFAULT_FLUS_TIMEOUT_MS = 32 ;
5
5
6
6
export class SimpleBuffer implements Disposable {
7
- private readonly flush : ( ) => void ;
8
7
private readonly chunks = Chunks . create ( ) ;
8
+ private readonly flush : ( ) => void ;
9
9
private flushInterval ?: NodeJS . Timeout ;
10
10
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 ) ;
15
18
this . clearChunks ( ) ;
16
19
onFlush ( chunks ) ;
17
20
}
18
21
} ;
19
-
20
- this . flush = flush ;
21
- this . flushInterval = setInterval ( flush , flushTimeout ) ;
22
+ this . flushInterval = setInterval ( this . flush , flushTimeout ) ;
22
23
}
23
24
24
- public addChunk (
25
+ addChunk (
25
26
chunk : Uint8Array ,
26
27
severity : OutputMessage . Severity = OutputMessage . Severity . Info
27
28
) : void {
@@ -32,10 +33,8 @@ export class SimpleBuffer implements Disposable {
32
33
Chunks . clear ( this . chunks ) ;
33
34
}
34
35
35
- public clearFlushInterval ( ) : void {
36
+ dispose ( ) : void {
36
37
this . flush ( ) ;
37
- this . clearChunks ( ) ;
38
-
39
38
clearInterval ( this . flushInterval ) ;
40
39
this . clearChunks ( ) ;
41
40
this . flushInterval = undefined ;
0 commit comments