From fd7d22e16ab6c9de274729ed945fe7f04d24f639 Mon Sep 17 00:00:00 2001 From: Tyler Hallada Date: Sat, 19 Mar 2022 01:20:24 -0400 Subject: [PATCH] Enable processing plugins as soon as there is one available worker --- components/DataDirPicker.tsx | 2 +- components/DropZone.tsx | 4 ++-- lib/WorkerPool.ts | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) 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; }