]> zoso.dev Git - libnemo.git/commitdiff
Refactor returned promises.
authorChris Duncan <chris@zoso.dev>
Tue, 7 Jan 2025 00:30:41 +0000 (16:30 -0800)
committerChris Duncan <chris@zoso.dev>
Tue, 7 Jan 2025 00:30:41 +0000 (16:30 -0800)
src/lib/workers/powgpu.ts

index 3acd609304fb369d9eb648a57570d8d96a71965f..04c7198c48d24f104b8a195dbf3a0cfc4bf6e21f 100644 (file)
@@ -22,9 +22,7 @@ export class PowGpu extends WorkerInterface {
                return new Promise(async (resolve, reject): Promise<void> => {
                        for (const d of data) {
                                try {
-                                       d.work = await new Promise<string>(async (resolve): Promise<void> => {
-                                               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)
                }
        }
 }