Skip to content

PyodideRuntime.run should not await #879

@antocuni

Description

@antocuni

I noticed this while looking at the source code.

Runtime.run is marked async:

/**
* delegates the code to be run to the underlying interpreter
* (asynchronously) which can call its own API behind the scenes.
* Python exceptions are turned into JS exceptions.
* */
abstract run(code: string): Promise<any>;

But then when we call pyodide we do the following:

async run(code: string): Promise<any> {
return await this.interpreter.runPythonAsync(code);
}

Note the return await, which should probably be just a return. I'm not fully sure of the implications of doing the await here but I guess it causes code to be less parallel that it should be.

I think that it means that if we do the following:

await Promise.all([
    runtime.run(src1),
    runtime.run(src2),
    runtime.run(src3)
]);

src1, src2 and src3 will not be executed in parallel but sequentially.

In general, I think we have a problem with our usage of async in our codebase: we use them a bit too freely and without really understanding what's going on (or at least: personally I don't fully understand what's going on: if you do, please explain to me :)).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Status

    Closed

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy