Optionalconfig: Partial<BaseWorkerPoolConfig>Initializes the shared worker pool. Should be called by subclasses via super.initialize() or independently.
async initialize(): Promise<void> {
if (this.initialized) {
return;
}
try {
const pool = getGenericWorkerPool();
await pool.initialize();
this.initialized = true;
console.info(`[${this.getPoolName()}] Pool initialized`);
} catch (error) {
console.warn(`[${this.getPoolName()}] Failed to initialize pool:`, error);
// Still mark as initialized to use main thread fallback
this.initialized = true;
}
}
Returns initialization and availability stats.
Status object
Aggregates statistics using workers when available, otherwise on the main thread.
Normalized match results for statistics.
Reading history to correlate.
Active statistics filter configuration.
Comparison mode configuration.
Selected time range for aggregation.
OptionalprogressCallback: (stage: string, progress: number, message: string) => voidOptional callback for progress updates.
OptionaltaskId: stringOptional task identifier.
Aggregation result with datasets, cache key, and timing.
async aggregateStatistics(
matchResults: NormalizedMatchForStats[],
readingHistory: ReadingHistory,
filters: StatisticsFilters,
comparisonMode: ComparisonMode,
selectedTimeRange: TimeRange,
progressCallback?: (
stage: string,
progress: number,
message: string,
) => void,
taskId?: string,
): Promise<StatisticsAggregationResult> {
const mainTaskId = taskId || generateUUID();
await this.ensureInitialized();
return this.executeWithFallback(
() =>
this.executeOnWorker(
mainTaskId,
matchResults,
readingHistory,
filters,
comparisonMode,
selectedTimeRange,
progressCallback,
),
() =>
this.aggregateStatisticsMainThread(
matchResults,
readingHistory,
filters,
comparisonMode,
selectedTimeRange,
),
mainTaskId,
);
}
Returns pool statistics for the underlying generic worker pool. Provides detailed metrics about active workers and tasks.
Pool statistics including total workers, active workers, and active tasks.
Singleton-backed worker pool for statistics aggregation with main-thread fallback.
Source