@peerbit/native-backbone 0.1.1 → 0.1.2

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.
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@peerbit/native-backbone",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "description": "Native transaction backbone for Peerbit",
5
5
  "sideEffects": [
6
6
  "./dist/wasm/native_backbone.js"
package/src/index.ts CHANGED
@@ -2116,6 +2116,7 @@ type WasmModule = {
2116
2116
 
2117
2117
  let wasmModulePromise: Promise<WasmModule> | undefined;
2118
2118
  let wasmInitialized = false;
2119
+ let wasmInitPromise: Promise<void> | undefined;
2119
2120
 
2120
2121
  const loadWasm = async (): Promise<WasmModule> => {
2121
2122
  if (!wasmModulePromise) {
@@ -2127,28 +2128,31 @@ const loadWasm = async (): Promise<WasmModule> => {
2127
2128
 
2128
2129
  const wasm = await wasmModulePromise;
2129
2130
  if (!wasmInitialized) {
2130
- const processLike = (
2131
- globalThis as { process?: { versions?: { node?: string } } }
2132
- ).process;
2133
- if (processLike?.versions?.node) {
2134
- const fsPromises = "fs/promises";
2135
- const { readFile } = (await import(
2136
- /* @vite-ignore */ fsPromises
2137
- )) as typeof import("fs/promises");
2138
- const bytes = await readFile(
2139
- new URL("../wasm/native_backbone_bg.wasm", import.meta.url),
2140
- );
2141
- wasm.initSync({ module: bytes });
2142
- } else {
2143
- await wasm.default({
2144
- module_or_path: new URL(
2145
- "../wasm/native_backbone_bg.wasm",
2146
- import.meta.url,
2147
- ),
2148
- });
2149
- }
2150
- wasmInitialized = true;
2131
+ wasmInitPromise ??= (async () => {
2132
+ const processLike = (
2133
+ globalThis as { process?: { versions?: { node?: string } } }
2134
+ ).process;
2135
+ if (processLike?.versions?.node) {
2136
+ const fsPromises = "fs/promises";
2137
+ const { readFile } = (await import(
2138
+ /* @vite-ignore */ fsPromises
2139
+ )) as typeof import("fs/promises");
2140
+ const bytes = await readFile(
2141
+ new URL("../wasm/native_backbone_bg.wasm", import.meta.url),
2142
+ );
2143
+ wasm.initSync({ module: bytes });
2144
+ } else {
2145
+ await wasm.default({
2146
+ module_or_path: new URL(
2147
+ "../wasm/native_backbone_bg.wasm",
2148
+ import.meta.url,
2149
+ ),
2150
+ });
2151
+ }
2152
+ wasmInitialized = true;
2153
+ })();
2151
2154
  }
2155
+ await wasmInitPromise;
2152
2156
 
2153
2157
  return wasm;
2154
2158
  };