From: Chris Duncan Date: Mon, 6 Jan 2025 17:37:04 +0000 (-0800) Subject: Wait a maximum of 8 seconds to load GPU. X-Git-Url: https://zoso.dev/?a=commitdiff_plain;h=dc5da297835aabb2f57a3f357d25485ede02cf75;p=libnemo.git Wait a maximum of 8 seconds to load GPU. --- 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 }