From: Chris Duncan Date: Tue, 3 Mar 2026 14:56:02 +0000 (-0800) Subject: Rename some host code variables to reduce esbuild collision detection. X-Git-Tag: v1.0.0~14 X-Git-Url: https://git.codecow.com/?a=commitdiff_plain;h=d915aadf707f26d5fd2413df47318acb19d5e014;p=nano25519.git Rename some host code variables to reduce esbuild collision detection. --- diff --git a/index.ts b/index.ts index a7e4fb6..79583ab 100644 --- a/index.ts +++ b/index.ts @@ -221,31 +221,31 @@ const NanoNaClWorker = `;await (${NanoNaCl})([${nacl}])` */ // Initialize CPU -let isReady: boolean = false +let isWorkerReady: boolean = false let worker: Worker let url: string -function setup (): void { +function init (): void { try { url = URL.createObjectURL(new Blob([NanoNaClWorker], { type: 'text/javascript' })) worker = new Worker(url, { type: 'module' }) console.log(`NanoNaCl initialized.`) - isReady = true + isWorkerReady = true } catch (err) { - isReady = false + isWorkerReady = false throw new Error('NanoNaCl initialization failed.', { cause: err }) } } function reset (): void { console.warn(`NanoNaCl encountered an error. Reinitializing...`) - isReady = false + isWorkerReady = false worker.terminate() - setup() + init() } -async function init (): Promise { - if (!isReady) setup() +async function start (): Promise { + if (!isWorkerReady) init() return new Promise(async (ready, fail): Promise => { worker.onmessage = msg => msg.data === 'started' ? ready(msg.data) : fail(msg.data) worker.onerror = err => fail(err.message) @@ -284,7 +284,7 @@ async function stop (): Promise { async function run (data: Record): Promise { try { - await init() + await start() } catch (err) { console.error(err) throw new Error('Error initializing worker')