Skip to content
This repository has been archived by the owner on May 8, 2023. It is now read-only.

NodeJS WASM loading async but calls maybe faster than async loading complete #29

Open
dmikey opened this issue Nov 15, 2022 · 0 comments

Comments

@dmikey
Copy link

dmikey commented Nov 15, 2022

Executing lit-js-sdk in an environment where a method will be executed before the wasm completes to load, will result in a

[Lit-JS-SDK] wasmExports is not loaded. error.

Screenshot 2022-11-14 at 8 21 18 PM

the promise is returned after the main thread is idle.

simple recreation

const LitJsSdk = require("lit-js-sdk");

const { verified, header, payload } = LitJsSdk.verifyJwt({
  jwt: "",
});

simple work around

const LitJsSdk = require("lit-js-sdk");

function checkLitWasm() {
  if (!globalThis.wasmExports) {
    setTimeout(
      checkLitWasm,
      100
    ); /* this checks the flag every 100 milliseconds*/
  } else {
    const { verified, header, payload } = LitJsSdk.verifyJwt({
      jwt: "",
    });
    console.log(verified, header, payload);
  }
}
checkLitWasm();
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant