Skip to content

--instantiation with non-async support #245

@Hywan

Description

@Hywan

Hello,

Thanks for the great project, it's really useful!
I'm using it in particular context where I need to use --instantation, thanks for providing this option! My problem is that the generated instantiate function is async:

function instantiate(
    compileCore: () => Promise<WebAssembly.Module>,
    imports: ImportObject,
    instantiateCore?: () => Promise<WebAssembly.Instance>,
): Promise<>

I need a non-async instantiate function, such as:

function instantiate(
    compileCore: () => WebAssembly.Module,
    imports: ImportObject,
    instantiateCore?: () => WebAssembly.Instance,
): 

I can work on this patch, but I would like to align on a couple of things beforehand:

  1. Are you willing to merge such a feature?
  2. Ideally, we want to keep --instantiation, but I would “duplicate” the option with --instantation-no-async. Internally, we would keep the TranspileOpts::instantiation field, but a new TranspileOpts::instantiation_is_async field would be added:
    • --instantiation would result in TranspileOpts { instantiation: true, instantiation_is_async: true }
    • --instantiation-no-async would result in TranspileOpts { instantiation: true, instantiation_is_async: false }.

One could argue that I could str::replace the output of JCO to replace async function by function, await by nothing, Promise.all… by nothing and so on, but I believe this problem might appear for other users, and having this implemented inside JCO directly would be less hacky.

Thoughts?

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions