webassembly/proxy_js: Promote Python thenable to a Promise.
Signed-off-by: Damien George <damien@micropython.org>
This commit is contained in:
31
tests/ports/webassembly/fun_py_callback_js.mjs
Normal file
31
tests/ports/webassembly/fun_py_callback_js.mjs
Normal file
@@ -0,0 +1,31 @@
|
||||
// Test using Python functions as JS callbacks.
|
||||
|
||||
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")
|
||||
|
||||
async def f1():
|
||||
print("f1 run")
|
||||
|
||||
async def f2():
|
||||
print("f2 start")
|
||||
await js.asyncTimeout(0)
|
||||
print("f2 end")
|
||||
|
||||
async def f3():
|
||||
print("f3 start")
|
||||
await f2()
|
||||
print("f3 end")
|
||||
|
||||
js.setTimeout(f0, 0)
|
||||
js.setTimeout(f1, 50)
|
||||
js.setTimeout(f2, 100)
|
||||
js.setTimeout(f3, 150)
|
||||
`);
|
||||
8
tests/ports/webassembly/fun_py_callback_js.mjs.exp
Normal file
8
tests/ports/webassembly/fun_py_callback_js.mjs.exp
Normal file
@@ -0,0 +1,8 @@
|
||||
f0 run
|
||||
f1 run
|
||||
f2 start
|
||||
f2 end
|
||||
f3 start
|
||||
f2 start
|
||||
f2 end
|
||||
f3 end
|
||||
Reference in New Issue
Block a user