import { analyzeDecisionTree } from '../solver/decisionTree'; import type { OptimizationMode } from '../data/types'; import type { SetAnalysis } from '../solver/decisionTree'; export interface WorkerRequest { pinnedCourseIds: string[]; openSetIds: string[]; ranking: string[]; mode: OptimizationMode; excludedCourseIds?: string[]; } export interface WorkerResponse { type: 'setComplete' | 'allComplete'; analysis?: SetAnalysis; analyses?: SetAnalysis[]; } self.onmessage = (e: MessageEvent) => { const { pinnedCourseIds, openSetIds, ranking, mode, excludedCourseIds } = e.data; const excludedSet = excludedCourseIds && excludedCourseIds.length > 0 ? new Set(excludedCourseIds) : undefined; const analyses = analyzeDecisionTree( pinnedCourseIds, openSetIds, ranking, mode, (analysis) => { // Progressive update: send each set's results as they complete const response: WorkerResponse = { type: 'setComplete', analysis }; self.postMessage(response); }, excludedSet, ); // Final result with sorted analyses const response: WorkerResponse = { type: 'allComplete', analyses }; self.postMessage(response); };