Skip to content

Commit 3f34be6

Browse files
committed
webassembly/asyncio: Fix case where a Promise is resolved with no arg.
Signed-off-by: Damien George <damien@micropython.org>
1 parent c37eb93 commit 3f34be6

3 files changed

Lines changed: 27 additions & 1 deletion

File tree

ports/webassembly/asyncio/core.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ def __init__(self, thenable):
7575
self.waiting = None # Task waiting on completion of this thenable
7676
thenable.then(self.set)
7777

78-
def set(self, value):
78+
def set(self, value=None):
7979
# Thenable/Promise is fulfilled, set result and schedule any waiting task.
8080
self.result = value
8181
if self.waiting:
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Test an asyncio task await'ing on a Promise that's resolved without an argument.
2+
3+
const mp = await (await import(process.argv[2])).loadMicroPython();
4+
5+
globalThis.foo = new Promise((resolve) => {
6+
console.log(1);
7+
resolve(); // resolve without an argument
8+
console.log(2);
9+
});
10+
11+
mp.runPython(`
12+
import asyncio
13+
import js
14+
15+
async def task():
16+
print(3)
17+
print(await js.foo)
18+
print(4)
19+
20+
asyncio.create_task(task())
21+
`);
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
1
2+
2
3+
3
4+
None
5+
4

0 commit comments

Comments
 (0)