webassembly/asyncio: Fix case where a Promise is resolved with no arg.
Signed-off-by: Damien George <damien@micropython.org>
This commit is contained in:
@@ -75,7 +75,7 @@ class ThenableEvent:
|
|||||||
self.waiting = None # Task waiting on completion of this thenable
|
self.waiting = None # Task waiting on completion of this thenable
|
||||||
thenable.then(self.set)
|
thenable.then(self.set)
|
||||||
|
|
||||||
def set(self, value):
|
def set(self, value=None):
|
||||||
# Thenable/Promise is fulfilled, set result and schedule any waiting task.
|
# Thenable/Promise is fulfilled, set result and schedule any waiting task.
|
||||||
self.result = value
|
self.result = value
|
||||||
if self.waiting:
|
if self.waiting:
|
||||||
|
|||||||
21
tests/ports/webassembly/asyncio_await_resolve_no_arg.mjs
Normal file
21
tests/ports/webassembly/asyncio_await_resolve_no_arg.mjs
Normal file
@@ -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())
|
||||||
|
`);
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
1
|
||||||
|
2
|
||||||
|
3
|
||||||
|
None
|
||||||
|
4
|
||||||
Reference in New Issue
Block a user