]> zoso.dev Git - libnemo.git/commitdiff
Wait a maximum of 8 seconds to load GPU.
authorChris Duncan <chris@zoso.dev>
Mon, 6 Jan 2025 17:37:04 +0000 (09:37 -0800)
committerChris Duncan <chris@zoso.dev>
Mon, 6 Jan 2025 17:37:04 +0000 (09:37 -0800)
src/lib/workers/powgpu.ts

index 30401fcb5775246500e6fc6cc67e691ea92ffd08..8a781ec6bfc71134cba31ad05ba0d60823f79458 100644 (file)
@@ -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
                }