• Executes batch matching on the main thread as a fallback.

    Parameters

    • kenmeiMangaList: KenmeiManga[]

      Kenmei manga to match.

    • anilistCandidatesMap: Map<string, AniListManga[]>

      Candidate AniList entries keyed by index.

    • config: Partial<MatchEngineConfig> = {}

      Matching engine configuration overrides.

    • OptionalprogressCallback: (current: number, total: number, currentTitle?: string) => void

      Optional progress callback.

    Returns Promise<MangaMatchResult[]>

    Promise resolving to match results.

    export async function executeMatchingOnMainThread(
    kenmeiMangaList: KenmeiManga[],
    anilistCandidatesMap: Map<string, AniListManga[]>,
    config: Partial<MatchEngineConfig> = {},
    progressCallback?: (
    current: number,
    total: number,
    currentTitle?: string,
    ) => void,
    ): Promise<MangaMatchResult[]> {
    const results: MangaMatchResult[] = [];
    const total = kenmeiMangaList.length;

    for (let i = 0; i < total; i++) {
    const manga = kenmeiMangaList[i];
    // Use index-based key to match worker and results.ts convention
    const candidates = anilistCandidatesMap.get(String(i)) || [];

    const matchResult = findBestMatches(
    manga,
    candidates,
    config as MatchEngineConfig,
    );
    results.push(matchResult);

    if (progressCallback) {
    progressCallback(i + 1, total, manga.title);
    }

    // Yield to event loop periodically to keep UI responsive
    if (i % 10 === 0) {
    await new Promise((resolve) => setTimeout(resolve, 0));
    }
    }

    return results;
    }