summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ports/webassembly/api.js10
1 files changed, 10 insertions, 0 deletions
diff --git a/ports/webassembly/api.js b/ports/webassembly/api.js
index 2f2ad9522..2be82e890 100644
--- a/ports/webassembly/api.js
+++ b/ports/webassembly/api.js
@@ -228,6 +228,16 @@ async function runCLI() {
}
});
} else {
+ // If the script to run ends with a running of the asyncio main loop, then inject
+ // a simple `asyncio.run` hook that starts the main task. This is primarily to
+ // support running the standard asyncio tests.
+ if (contents.endsWith("asyncio.run(main())\n")) {
+ const asyncio = mp.pyimport("asyncio");
+ asyncio.run = async (task) => {
+ await asyncio.create_task(task);
+ };
+ }
+
try {
mp.runPython(contents);
} catch (error) {