Skip to content

make dynamic import actually async #196

Closed

Description

@codehz

#191 (comment)

The core idea is to change the js_dynamic_import_job to make it actually async

maybe could add a new hook to handle dynamic import, choose to resolve the promise directly or resolve it later

Activity

  1. saghul commented on Dec 10, 2023

    @saghul
    Contributor

    Please don't open a new issue. Keep the discussion on #191.

  2. bnoordhuis commented on Dec 10, 2023

    @bnoordhuis
    Contributor

    I asked him to open a new issue because dynamic import is different from regular import.

    edit: that said, the conclusion may still be that we're not going to change anything.

  3. added
    enhancement
    on Dec 10, 2023
  4. saghul commented on Dec 10, 2023

    @saghul
    Contributor

    Ops my bad! Understood.

  5. karlseguin commented on Oct 17, 2025

    @karlseguin
    Contributor

    If I understand this request, I think it's something I'd also be interested in.

    Currently, we register our module loading callback using JS_SetModuleLoaderFunc. We need to return a *JSModuleDef which requires that we JS_Eval2 the source of the module.

    V8 uses a distinct callback for dynamic modules, SetHostImportModuleDynamicallyCallback, which expects a promise to be returned. This makes a lot of sense to me, because loading a dynamic module shouldn't itself be blocking. It also makes it easier to integrate with nonblocking I/O, because we can associate the Promise with our nonblocking I/O operation and, on completion, resolve the promise.

    Some websites do hundreds of dynamic async imports, and I'm having a hard time figuring out how to do this efficiently in QuickJS.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions