diff --git a/components/DataDirPicker.tsx b/components/DataDirPicker.tsx index f457f57..04e7450 100644 --- a/components/DataDirPicker.tsx +++ b/components/DataDirPicker.tsx @@ -30,7 +30,7 @@ const DataDirPicker: React.FC = () => { const onDataDirButtonClick = async (event: { target: { files: FileList | null }; }) => { - if (!workerPool) { + if (!workerPool || workerPool.availableWorkers.length === 0) { return alert("Workers not loaded yet"); } const files = event.target.files ?? []; diff --git a/components/DropZone.tsx b/components/DropZone.tsx index 7195ea0..389fe19 100644 --- a/components/DropZone.tsx +++ b/components/DropZone.tsx @@ -58,7 +58,7 @@ export const DropZone: React.FC = ({ children, workerPool }) => { const pluginFiles = await Promise.all( plugins.map(async (plugin) => plugin.getFile()) ); - if (workerPool) { + if (workerPool && workerPool.availableWorkers.length > 0) { parsePluginFiles(pluginFiles, workerPool); } else { alert("Workers not loaded yet"); @@ -117,7 +117,7 @@ export const DropZone: React.FC = ({ children, workerPool }) => { ) ) ); - if (workerPool) { + if (workerPool && workerPool.availableWorkers.length > 0) { parsePluginFiles(pluginFiles, workerPool); } else { alert("Workers not loaded yet"); diff --git a/lib/WorkerPool.ts b/lib/WorkerPool.ts index 9dcfba1..5a1cccc 100644 --- a/lib/WorkerPool.ts +++ b/lib/WorkerPool.ts @@ -26,7 +26,7 @@ export class WorkerPool { public async init(count: number = window.navigator.hardwareConcurrency ?? 8): Promise { this.availableWorkers = []; for (let i = 0; i < count; i++) { - this.availableWorkers.push(await this.createWorker()); + this.createWorker().then(worker => this.availableWorkers.push(worker)); } return this; }