From 005d04d9ff7512687f58492a8fefa1908381f691 Mon Sep 17 00:00:00 2001 From: Chris Duncan Date: Mon, 6 Jan 2025 16:30:41 -0800 Subject: [PATCH] Refactor returned promises. --- src/lib/workers/powgpu.ts | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/lib/workers/powgpu.ts b/src/lib/workers/powgpu.ts index 3acd609..04c7198 100644 --- a/src/lib/workers/powgpu.ts +++ b/src/lib/workers/powgpu.ts @@ -22,9 +22,7 @@ export class PowGpu extends WorkerInterface { return new Promise(async (resolve, reject): Promise => { for (const d of data) { try { - d.work = await new Promise(async (resolve): Promise => { - await this.search(d.hash, resolve, d.threshold) - }) + d.work = await this.search(d.hash, d.threshold) } catch (err) { reject(err) } @@ -479,8 +477,11 @@ export class PowGpu extends WorkerInterface { if (performance.now() > 8000) { throw new Error(`WebGPU device failed to load in time.`) } - setTimeout(async () => { await this.search(hashHex, threshold) }, 100) - return + return await new Promise(resolve => { + setTimeout(() => { + resolve(this.search(hashHex, threshold)) + }, 100) + }) } @@ -552,7 +553,7 @@ export class PowGpu extends WorkerInterface { const hex = nonce.toString(16).padStart(16, '0') return hex } else { - setTimeout(async () => { return await this.search(hashHex, threshold) }) + return await this.search(hashHex, threshold) } } } -- 2.34.1