From d915aadf707f26d5fd2413df47318acb19d5e014 Mon Sep 17 00:00:00 2001 From: Chris Duncan Date: Tue, 3 Mar 2026 06:56:02 -0800 Subject: [PATCH] Rename some host code variables to reduce esbuild collision detection. --- index.ts | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) 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') -- 2.47.3