@@ -11,11 +11,13 @@ import { dispatch } from "../event.ts";
11
11
const INTERVAL = 0 ;
12
12
const THRESHOLD = 10000 ;
13
13
const CHUNK_SIZE = 1000 ;
14
+ const CHUNK_INTERVAL = 100 ;
14
15
15
16
export type MatchProcessorOptions = {
16
17
interval ?: number ;
17
18
threshold ?: number ;
18
19
chunkSize ?: number ;
20
+ chunkInterval ?: number ;
19
21
incremental ?: boolean ;
20
22
} ;
21
23
@@ -24,6 +26,7 @@ export class MatchProcessor<T extends Detail> implements Disposable {
24
26
readonly #interval: number ;
25
27
readonly #threshold: number ;
26
28
readonly #chunkSize: number ;
29
+ readonly #chunkInterval: number ;
27
30
readonly #incremental: boolean ;
28
31
#controller: AbortController = new AbortController ( ) ;
29
32
#processing?: Promise < void > ;
@@ -38,6 +41,7 @@ export class MatchProcessor<T extends Detail> implements Disposable {
38
41
this . #interval = options . interval ?? INTERVAL ;
39
42
this . #threshold = options . threshold ?? THRESHOLD ;
40
43
this . #chunkSize = options . chunkSize ?? CHUNK_SIZE ;
44
+ this . #chunkInterval = options . chunkInterval ?? CHUNK_INTERVAL ;
41
45
this . #incremental = options . incremental ?? false ;
42
46
}
43
47
@@ -109,9 +113,14 @@ export class MatchProcessor<T extends Detail> implements Disposable {
109
113
}
110
114
} ;
111
115
const chunker = new Chunker < IdItem < T > > ( this . #chunkSize) ;
116
+ let lastChunkTime = performance . now ( ) ;
112
117
for await ( const item of iter ) {
113
118
signal . throwIfAborted ( ) ;
114
- if ( chunker . put ( item ) ) {
119
+ if (
120
+ chunker . put ( item ) ||
121
+ performance . now ( ) - lastChunkTime > this . #chunkInterval
122
+ ) {
123
+ lastChunkTime = performance . now ( ) ;
115
124
update ( chunker . consume ( ) ) ;
116
125
await delay ( this . #interval, { signal } ) ;
117
126
}
0 commit comments