mirror of
https://github.com/micropython/micropython.git
synced 2025-09-07 02:10:52 +02:00
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>
25 lines
526 B
JavaScript
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.
|