fix: duplicate wasm initialization

feat/type-attributes
Tomáš Mládek 2023-08-27 11:48:44 +02:00
parent bba4dc3041
commit b3d6866c7c
1 changed files with 12 additions and 2 deletions

View File

@ -13,7 +13,7 @@ import type {
StoreInfo,
VaultInfo,
} from "./types";
import init_wasm from "upend_wasm";
import init_wasm, { InitOutput } from "upend_wasm";
import {
AddressComponents,
AddressTypeConstants,
@ -27,8 +27,10 @@ export { AddressComponents };
export class UpEndApi {
private instanceUrl = "";
private wasmPath: string | undefined;
private wasmInitialized = false;
private wasmPromise: Promise<InitOutput> | undefined;
private addressTypeConstants: AddressTypeConstants | undefined = undefined;
private queryOnceLRU = new LRU<string, UpListing>({ max: 128 });
@ -265,7 +267,15 @@ export class UpEndApi {
"Path to WASM file not specified, cannot initialize WASM extensions."
);
}
await init_wasm(this.wasmPath);
if (this.wasmPromise) {
await this.wasmPromise;
} else {
dbg("Initializing WASM...");
this.wasmPromise = init_wasm(this.wasmPath);
await this.wasmPromise;
dbg("Wasm initialized.");
}
this.wasmInitialized = true;
}
}