From: Chris Duncan Date: Tue, 9 Sep 2025 04:00:39 +0000 (-0700) Subject: Eliminate redundant assignment function. X-Git-Tag: v0.10.5~24^2~3 X-Git-Url: https://git.codecow.com/?a=commitdiff_plain;h=5ca6e3346c3d0f5abbfbdecfd7d726374b7e562a;p=libnemo.git Eliminate redundant assignment function. --- 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