webassembly/proxy_c: Ensure return value of async fun is passed to JS.
Signed-off-by: Damien George <damien@micropython.org>
This commit is contained in:
35
tests/ports/webassembly/await_js_async_py.mjs
Normal file
35
tests/ports/webassembly/await_js_async_py.mjs
Normal file
@@ -0,0 +1,35 @@
|
||||
// Test JavaScript await'ing on Python async functions.
|
||||
|
||||
const mp = await (await import(process.argv[2])).loadMicroPython();
|
||||
|
||||
globalThis.asyncTimeout = (ms) =>
|
||||
new Promise((resolve) => setTimeout(resolve, ms));
|
||||
|
||||
mp.runPython(`
|
||||
import js
|
||||
|
||||
def f0():
|
||||
print("f0 run")
|
||||
return 1
|
||||
|
||||
async def f1():
|
||||
print("f1 run")
|
||||
return 2
|
||||
|
||||
async def f2():
|
||||
print("f2 start")
|
||||
await js.asyncTimeout(0)
|
||||
print("f2 end")
|
||||
return 3
|
||||
|
||||
async def f3():
|
||||
print("f3 start")
|
||||
ret = await f2()
|
||||
print("f3 end")
|
||||
return ret + 1
|
||||
`);
|
||||
|
||||
console.log("f0 return:", await mp.globals.get("f0")());
|
||||
console.log("f1 return:", await mp.globals.get("f1")());
|
||||
console.log("f2 return:", await mp.globals.get("f2")());
|
||||
console.log("f3 return:", await mp.globals.get("f3")());
|
||||
12
tests/ports/webassembly/await_js_async_py.mjs.exp
Normal file
12
tests/ports/webassembly/await_js_async_py.mjs.exp
Normal file
@@ -0,0 +1,12 @@
|
||||
f0 run
|
||||
f0 return: 1
|
||||
f1 run
|
||||
f1 return: 2
|
||||
f2 start
|
||||
f2 end
|
||||
f2 return: 3
|
||||
f3 start
|
||||
f2 start
|
||||
f2 end
|
||||
f3 end
|
||||
f3 return: 4
|
||||
Reference in New Issue
Block a user