@@ -11,11 +11,13 @@ import { dispatch } from "../event.ts";
1111const INTERVAL = 0 ;
1212const THRESHOLD = 10000 ;
1313const CHUNK_SIZE = 1000 ;
14+ const CHUNK_INTERVAL = 100 ;
1415
1516export type MatchProcessorOptions = {
1617 interval ?: number ;
1718 threshold ?: number ;
1819 chunkSize ?: number ;
20+ chunkInterval ?: number ;
1921 incremental ?: boolean ;
2022} ;
2123
@@ -24,6 +26,7 @@ export class MatchProcessor<T extends Detail> implements Disposable {
2426 readonly #interval: number ;
2527 readonly #threshold: number ;
2628 readonly #chunkSize: number ;
29+ readonly #chunkInterval: number ;
2730 readonly #incremental: boolean ;
2831 #controller: AbortController = new AbortController ( ) ;
2932 #processing?: Promise < void > ;
@@ -38,6 +41,7 @@ export class MatchProcessor<T extends Detail> implements Disposable {
3841 this . #interval = options . interval ?? INTERVAL ;
3942 this . #threshold = options . threshold ?? THRESHOLD ;
4043 this . #chunkSize = options . chunkSize ?? CHUNK_SIZE ;
44+ this . #chunkInterval = options . chunkInterval ?? CHUNK_INTERVAL ;
4145 this . #incremental = options . incremental ?? false ;
4246 }
4347
@@ -109,9 +113,14 @@ export class MatchProcessor<T extends Detail> implements Disposable {
109113 }
110114 } ;
111115 const chunker = new Chunker < IdItem < T > > ( this . #chunkSize) ;
116+ let lastChunkTime = performance . now ( ) ;
112117 for await ( const item of iter ) {
113118 signal . throwIfAborted ( ) ;
114- if ( chunker . put ( item ) ) {
119+ if (
120+ chunker . put ( item ) ||
121+ performance . now ( ) - lastChunkTime > this . #chunkInterval
122+ ) {
123+ lastChunkTime = performance . now ( ) ;
115124 update ( chunker . consume ( ) ) ;
116125 await delay ( this . #interval, { signal } ) ;
117126 }
0 commit comments