Skip to content

Commit

Permalink
webassembly/asyncio: Fix case where a Promise is resolved with no arg.
Browse files Browse the repository at this point in the history
Signed-off-by: Damien George <damien@micropython.org>
  • Loading branch information
dpgeorge committed May 13, 2024
1 parent c37eb93 commit 3f34be6
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
2 changes: 1 addition & 1 deletion ports/webassembly/asyncio/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def __init__(self, thenable):
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:
Expand Down
21 changes: 21 additions & 0 deletions tests/ports/webassembly/asyncio_await_resolve_no_arg.mjs
Original file line number Diff line number Diff line change
@@ -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 changes: 5 additions & 0 deletions tests/ports/webassembly/asyncio_await_resolve_no_arg.mjs.exp
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
1
2
3
None
4

0 comments on commit 3f34be6

Please sign in to comment.