fix: duplicate wasm initialization
parent
bba4dc3041
commit
b3d6866c7c
|
@ -13,7 +13,7 @@ import type {
|
||||||
StoreInfo,
|
StoreInfo,
|
||||||
VaultInfo,
|
VaultInfo,
|
||||||
} from "./types";
|
} from "./types";
|
||||||
import init_wasm from "upend_wasm";
|
import init_wasm, { InitOutput } from "upend_wasm";
|
||||||
import {
|
import {
|
||||||
AddressComponents,
|
AddressComponents,
|
||||||
AddressTypeConstants,
|
AddressTypeConstants,
|
||||||
|
@ -27,8 +27,10 @@ export { AddressComponents };
|
||||||
|
|
||||||
export class UpEndApi {
|
export class UpEndApi {
|
||||||
private instanceUrl = "";
|
private instanceUrl = "";
|
||||||
|
|
||||||
private wasmPath: string | undefined;
|
private wasmPath: string | undefined;
|
||||||
private wasmInitialized = false;
|
private wasmInitialized = false;
|
||||||
|
private wasmPromise: Promise<InitOutput> | undefined;
|
||||||
private addressTypeConstants: AddressTypeConstants | undefined = undefined;
|
private addressTypeConstants: AddressTypeConstants | undefined = undefined;
|
||||||
|
|
||||||
private queryOnceLRU = new LRU<string, UpListing>({ max: 128 });
|
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."
|
"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;
|
this.wasmInitialized = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue