From 5ca6e3346c3d0f5abbfbdecfd7d726374b7e562a Mon Sep 17 00:00:00 2001 From: Chris Duncan Date: Mon, 8 Sep 2025 21:00:39 -0700 Subject: [PATCH] Eliminate redundant assignment function. --- src/lib/vault/index.ts | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/src/lib/vault/index.ts b/src/lib/vault/index.ts index ca5487b..646fad6 100644 --- a/src/lib/vault/index.ts +++ b/src/lib/vault/index.ts @@ -46,24 +46,10 @@ export class Vault { Vault.#instances.push(this) } - prioritize (data: NamedData): Promise> { - return this.#assign(data, task => this.#queue.unshift(task)) - } - request (data: NamedData): Promise> { - return this.#assign(data, task => this.#queue.push(task)) - } - - terminate (): void { - this.#job = undefined - this.#worker.terminate() - this.#isTerminated = true - } - - #assign (data: NamedData, enqueue: (task: Task) => number): Promise> { return new Promise((resolve, reject): void => { if (this.#isTerminated) { - reject('Worker terminated') + return reject('Worker terminated') } const task: Task = { id: performance.now(), @@ -71,11 +57,17 @@ export class Vault { resolve, reject } - enqueue(task) + this.#queue.push(task) if (this.#isIdle) this.#process() }) } + terminate (): void { + this.#job = undefined + this.#worker.terminate() + this.#isTerminated = true + } + #process = (): void => { this.#job = this.#queue.shift() this.#isIdle = this.#job == null -- 2.47.3