From: Chris Duncan Date: Sat, 23 Nov 2024 09:47:53 +0000 (-0800) Subject: No way to import in worker besides as modules, so start figuring out workarounds. X-Git-Url: https://zoso.dev/?a=commitdiff_plain;h=6b9c54a74a865d4e83256ee213a3619a537d8612;p=libnemo.git No way to import in worker besides as modules, so start figuring out workarounds. --- diff --git a/src/lib/workers/ckdBlake2b.ts b/src/lib/workers/ckdBlake2b.ts index 166d7ab..a966240 100644 --- a/src/lib/workers/ckdBlake2b.ts +++ b/src/lib/workers/ckdBlake2b.ts @@ -1,12 +1,15 @@ // SPDX-FileCopyrightText: 2024 Chris Duncan // SPDX-License-Identifier: GPL-3.0-or-later +import blake2b from 'blake2b' + async function ckdBlake2b () { - const { default: blake2b } = await import('blake2b') + let blake2b: any let addEventListener = globalThis.addEventListener let postMessage = globalThis.postMessage if (addEventListener == null || postMessage == null) { + blake2b = (await import('blake2b')).default const { isMainThread, parentPort } = await import('node:worker_threads') if (!isMainThread && parentPort) { addEventListener = Object.getPrototypeOf(parentPort).addListener.bind(parentPort)