]> zoso.dev Git - libnemo.git/commitdiff
Since pow is already so expensive, the overhead of creating workers is negligible...
authorChris Duncan <chris@zoso.dev>
Tue, 3 Dec 2024 21:01:59 +0000 (13:01 -0800)
committerChris Duncan <chris@zoso.dev>
Tue, 3 Dec 2024 21:01:59 +0000 (13:01 -0800)
src/lib/block.ts

index 349976232a0b7511e36ac9e70f5832afd7973a4c..1e409f9acba0d9683aad76ca6dd1329b26851738 100644 (file)
@@ -16,7 +16,6 @@ import { Pow } from './workers.js'
 * of three derived classes: SendBlock, ReceiveBlock, ChangeBlock.
 */
 abstract class Block {
-       #pool: Pool
        account: Account
        type: string = 'state'
        abstract subtype: 'send' | 'receive' | 'change'
@@ -38,7 +37,6 @@ abstract class Block {
                } else {
                        throw new TypeError('Invalid account')
                }
-               this.#pool = new Pool(Pow)
        }
 
        /**
@@ -84,11 +82,13 @@ abstract class Block {
        * A successful response sets the `work` property.
        */
        async pow (): Promise<void> {
+               const pool = new Pool(Pow)
                const data = {
                        "hash": this.previous
                }
-               const [{ work }] = await this.#pool.work('converge', [data])
+               const [{ work }] = await pool.work('converge', [data])
                this.work = work
+               pool.dismiss()
        }
 
        /**