fix: duplicate wasm initialization
parent
bba4dc3041
commit
b3d6866c7c
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue