@cfasim-ui/wasm 0.1.8 → 0.1.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +2 -2
  2. package/src/wasm.worker.ts +15 -10
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cfasim-ui/wasm",
3
- "version": "0.1.8",
3
+ "version": "0.1.10",
4
4
  "type": "module",
5
5
  "description": "WebAssembly integration for cfasim-ui",
6
6
  "license": "Apache-2.0",
@@ -20,7 +20,7 @@
20
20
  "./vite": "./src/vitePlugin.ts"
21
21
  },
22
22
  "dependencies": {
23
- "@cfasim-ui/shared": "0.1.8"
23
+ "@cfasim-ui/shared": "0.1.10"
24
24
  },
25
25
  "peerDependencies": {
26
26
  "vue": "^3.5.0"
@@ -12,20 +12,25 @@ interface WorkerMessage {
12
12
  }
13
13
 
14
14
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
15
- const loadedModules = new Map<string, Record<string, any>>();
15
+ const modulePromises = new Map<string, Promise<Record<string, any>>>();
16
16
 
17
17
  const baseUrl = import.meta.env.BASE_URL ?? "/";
18
18
 
19
19
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
20
- async function ensureModule(model: string): Promise<Record<string, any>> {
21
- const cached = loadedModules.get(model);
22
- if (cached) return cached;
23
-
24
- const url = `${self.location.origin}${baseUrl}wasm/${model}/${model}.js`;
25
- const mod = await import(/* @vite-ignore */ url);
26
- await mod.default();
27
- loadedModules.set(model, mod);
28
- return mod;
20
+ function ensureModule(model: string): Promise<Record<string, any>> {
21
+ if (!modulePromises.has(model)) {
22
+ const promise = (async () => {
23
+ const url = `${self.location.origin}${baseUrl}wasm/${model}/${model}.js`;
24
+ const mod = await import(/* @vite-ignore */ url);
25
+ await mod.default();
26
+ return mod;
27
+ })();
28
+ promise.catch(() => {
29
+ modulePromises.delete(model);
30
+ });
31
+ modulePromises.set(model, promise);
32
+ }
33
+ return modulePromises.get(model)!;
29
34
  }
30
35
 
31
36
  self.onmessage = async (event: MessageEvent<WorkerMessage>) => {