OptionalmaxWorkers: numberInitializes the shared worker pool or enables main-thread fallback.
async initialize(): Promise<void> {
if (this.isInitialized) {
return;
}
try {
const pool = getGenericWorkerPool();
await pool.initialize();
this.isInitialized = true;
console.info("[DataTableWorkerPool] Pool initialized");
} catch (error) {
console.warn("[DataTableWorkerPool] Failed to initialize pool:", error);
// Still mark as initialized to use main thread fallback
this.isInitialized = true;
}
}
Prepares a table data slice, preferring workers and falling back to the main thread.
Full manga dataset to slice from.
Inclusive start index of the slice.
Exclusive end index of the slice.
Number of items targeted per page/viewport.
Flags controlling which column values are precomputed.
Preparation result with formatted rows and metadata.
async prepareTableSlice(
data: KenmeiMangaItem[],
startIndex: number,
endIndex: number,
itemsPerPage: number,
columnVisibility: {
score: boolean;
chapters: boolean;
volumes: boolean;
lastRead: boolean;
},
): Promise<DataTablePreparationResult> {
const taskId = generateTaskId();
// Ensure pool is initialized
if (!this.isInitialized) {
await this.initialize();
}
try {
const pool = getGenericWorkerPool();
// Check if workers are available
if (!pool.isAvailable()) {
console.debug(
"[DataTableWorkerPool] No workers available, using main thread",
);
return this.executeOnMainThread(
data,
startIndex,
endIndex,
columnVisibility,
);
}
// Try to use worker
return await this.executeOnWorker(
pool,
taskId,
data,
startIndex,
endIndex,
itemsPerPage,
columnVisibility,
);
} catch (error) {
console.warn(
"[DataTableWorkerPool] Worker execution failed, falling back to main thread:",
error,
);
return this.executeOnMainThread(
data,
startIndex,
endIndex,
columnVisibility,
);
}
}
Shuts down the underlying worker pool and clears initialization state.
Coordinates worker-based and main-thread preparation of data table slices.
Source