Browse Source

webassembly/asyncio: Fix case where a Promise is resolved with no arg.

Signed-off-by: Damien George <damien@micropython.org>
pull/14457/head
Damien George 6 months ago
parent
commit
3f34be69c7
  1. 2
      ports/webassembly/asyncio/core.py
  2. 21
      tests/ports/webassembly/asyncio_await_resolve_no_arg.mjs
  3. 5
      tests/ports/webassembly/asyncio_await_resolve_no_arg.mjs.exp

2
ports/webassembly/asyncio/core.py

@ -75,7 +75,7 @@ class ThenableEvent:
self.waiting = None # Task waiting on completion of this thenable
thenable.then(self.set)
def set(self, value):
def set(self, value=None):
# Thenable/Promise is fulfilled, set result and schedule any waiting task.
self.result = value
if self.waiting:

21
tests/ports/webassembly/asyncio_await_resolve_no_arg.mjs

@ -0,0 +1,21 @@
// Test an asyncio task await'ing on a Promise that's resolved without an argument.
const mp = await (await import(process.argv[2])).loadMicroPython();
globalThis.foo = new Promise((resolve) => {
console.log(1);
resolve(); // resolve without an argument
console.log(2);
});
mp.runPython(`
import asyncio
import js
async def task():
print(3)
print(await js.foo)
print(4)
asyncio.create_task(task())
`);

5
tests/ports/webassembly/asyncio_await_resolve_no_arg.mjs.exp

@ -0,0 +1,5 @@
1
2
3
None
4
Loading…
Cancel
Save