Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Top level await is problematic #10

Closed
roninjin10 opened this issue Feb 21, 2024 · 1 comment
Closed

Top level await is problematic #10

roninjin10 opened this issue Feb 21, 2024 · 1 comment

Comments

@roninjin10
Copy link
Contributor

roninjin10 commented Feb 21, 2024

There is a top level await here: https://github.com/ethereumjs/rustbn-wasm/blob/master/src.ts/rustbn.ts#L159

This top level await is probematic. For build tools like vite and rollup it requires a special top level await plugin to be used correctly. For next.js with app router it throws a very confusing error

telegram-cloud-photo-size-4-5958752539329543627-y

A simple solution is to just wrap this await in a class

class RustBn {
   ready() {
      return true if instanciated
   }
   constructor() {
      // instanciate async here
   }
}

There might be better solutions for dealing with this with wasm that I'm unaware of.

Not wrapping it is a breaking change and would require changes to ethereumjs uses of this too. Would be nice if we could remove the top level await without breaking change

@roninjin10
Copy link
Contributor Author

Looked more into this and it is possible to instanciate the wasm module syncronously. But it's generally not ideal because it would make it impossible to use this library on the main thread in the browser as it would block the main thread with an expensive wasm compile.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants