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

Signed-off-by: Damien George <damien@micropython.org>
Damien George 2024-05-09 15:07:11 +10:00
rodzic 521b4280c9
commit 0a07cd8a91
3 zmienionych plików z 27 dodań i 1 usunięć

Wyświetl plik

@ -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:

Wyświetl plik

@ -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())
`);

Wyświetl plik

@ -0,0 +1,5 @@
1
2
3
None
4