From dc5da297835aabb2f57a3f357d25485ede02cf75 Mon Sep 17 00:00:00 2001 From: Chris Duncan Date: Mon, 6 Jan 2025 09:37:04 -0800 Subject: [PATCH] Wait a maximum of 8 seconds to load GPU. --- src/lib/workers/powgpu.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/lib/workers/powgpu.ts b/src/lib/workers/powgpu.ts index 30401fc..8a781ec 100644 --- a/src/lib/workers/powgpu.ts +++ b/src/lib/workers/powgpu.ts @@ -479,8 +479,11 @@ export class PowGpu extends WorkerInterface { if (!/^[A-Fa-f0-9]{64}$/.test(hashHex)) throw new Error(`Invalid hash ${hashHex}`) if (typeof threshold !== 'number') throw new TypeError(`Invalid threshold ${threshold}`) - // Ensure WebGPU is initialized else restart calculation + // Ensure WebGPU is initialized before calculating, up to a max time frame if (PowGpu.#device == null) { + if (performance.now() > 8000) { + throw new Error(`WebGPU device failed to load in time.`) + } setTimeout(async () => { await this.#calculate(hashHex, callback, threshold) }, 100) return } -- 2.34.1