Files
micropython/tests/ports/webassembly/run_python_async_no_await.mjs
Damien George be1ecb54e6 webassembly/api: Resolve thenables returned from runPythonAsync.
JavaScript semantics are such that the caller of an async function does not
need to await that function for it to run to completion.  This commit makes
that behaviour also apply to top-level async Python code run via
`runPythonAsync()`.

Signed-off-by: Damien George <damien@micropython.org>
2024-05-07 11:33:05 +10:00

25 lines
526 B
JavaScript

// Test runPythonAsync() without await'ing it.
const mp = await (await import(process.argv[2])).loadMicroPython();
globalThis.p = new Promise((resolve, reject) => {
setTimeout(() => {
resolve(123);
console.log("setTimeout resolved");
}, 100);
});
console.log(1);
const ret = mp.runPythonAsync(`
import js
print("py 1")
print("resolved value:", await js.p)
print("py 2")
`);
// `ret` should be a Promise.
console.log(2, ret);
// Here, the Python async code should continue to run until completed.