Array of Kenmei manga entries.
Async function to process each batch.
Batch size (default: 50).
Aggregated results from all batches.
export async function processMangaInBatches<T>(
entries: KenmeiManga[],
processFn: (batch: KenmeiManga[]) => Promise<T[]>,
batchSize = 50,
): Promise<T[]> {
return withGroupAsync(
`[KenmeiProcessor] Process Batches (${entries.length} entries)`,
async () => {
const results: T[] = [];
// Process in batches
for (let i = 0; i < entries.length; i += batchSize) {
const batch = entries.slice(i, i + batchSize);
if (batch.length === 0) continue;
const batchResults = await processFn(batch);
if (batchResults && batchResults.length > 0)
results.push(...batchResults);
}
return results;
},
);
}
Process manga entries in batches to avoid memory issues and enable progress tracking.