Skip to content

Commit

Permalink
fix loading wasm module concurrently #173
Browse files Browse the repository at this point in the history
  • Loading branch information
woodser committed Jan 25, 2024
1 parent 05dda67 commit a248d0a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 22 deletions.
32 changes: 11 additions & 21 deletions src/main/ts/common/LibraryUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,16 +86,11 @@ export default class LibraryUtils {
if (LibraryUtils.WASM_MODULE) return LibraryUtils.WASM_MODULE;

// load module
delete LibraryUtils.WASM_MODULE;
LibraryUtils.WASM_MODULE = require("../../../../dist/monero_wallet_keys")();
return new Promise(function(resolve, reject) {
LibraryUtils.WASM_MODULE.then(module => {
LibraryUtils.WASM_MODULE = module
delete LibraryUtils.WASM_MODULE.then;
LibraryUtils.initWasmModule(LibraryUtils.WASM_MODULE);
resolve(LibraryUtils.WASM_MODULE);
});
});
let module = await require("../../../../dist/monero_wallet_keys")();
LibraryUtils.WASM_MODULE = module
delete LibraryUtils.WASM_MODULE.then;
LibraryUtils.initWasmModule(LibraryUtils.WASM_MODULE);
return module;
}

/**
Expand All @@ -111,17 +106,12 @@ export default class LibraryUtils {
if (LibraryUtils.WASM_MODULE && LibraryUtils.FULL_LOADED) return LibraryUtils.WASM_MODULE;

// load module
delete LibraryUtils.WASM_MODULE;
LibraryUtils.WASM_MODULE = require("../../../../dist/monero_wallet_full")();
return new Promise(function(resolve, reject) {
LibraryUtils.WASM_MODULE.then(module => {
LibraryUtils.WASM_MODULE = module;
delete LibraryUtils.WASM_MODULE.then;
LibraryUtils.FULL_LOADED = true;
LibraryUtils.initWasmModule(LibraryUtils.WASM_MODULE);
resolve(LibraryUtils.WASM_MODULE);
});
});
let module = await require("../../../../dist/monero_wallet_full")();
LibraryUtils.WASM_MODULE = module
delete LibraryUtils.WASM_MODULE.then;
LibraryUtils.FULL_LOADED = true;
LibraryUtils.initWasmModule(LibraryUtils.WASM_MODULE);
return module;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/main/ts/common/MoneroUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ export default class MoneroUtils {
if (LibraryUtils.getWasmModule() === undefined) await LibraryUtils.loadKeysModule();

// get integrated address in queue
return LibraryUtils.getWasmModule().queueTask(async function() {
return LibraryUtils.getWasmModule().queueTask(async () => {
let integratedAddressJson = LibraryUtils.getWasmModule().get_integrated_address_util(networkType, standardAddress, paymentId ? paymentId : "");
if (integratedAddressJson.charAt(0) !== '{') throw new MoneroError(integratedAddressJson);
return new MoneroIntegratedAddress(JSON.parse(integratedAddressJson));
Expand Down

0 comments on commit a248d0a

Please sign in to comment.