webassembly/proxy_js: Promote Python thenable to a Promise.
Signed-off-by: Damien George <damien@micropython.org>
This commit is contained in:
@@ -89,7 +89,22 @@ function proxy_call_python(target, argumentsList) {
|
||||
if (argumentsList.length > 0) {
|
||||
Module._free(args);
|
||||
}
|
||||
return proxy_convert_mp_to_js_obj_jsside_with_free(value);
|
||||
const ret = proxy_convert_mp_to_js_obj_jsside_with_free(value);
|
||||
if (ret instanceof PyProxyThenable) {
|
||||
// In Python when an async function is called it creates the
|
||||
// corresponding "generator", which must then be executed at
|
||||
// the top level by an asyncio-like scheduler. In JavaScript
|
||||
// the semantics for async functions is that they are started
|
||||
// immediately (their non-async prefix code is executed immediately)
|
||||
// and only if they await do they return a Promise to delay the
|
||||
// execution of the remainder of the function.
|
||||
//
|
||||
// Emulate the JavaScript behaviour here by resolving the Python
|
||||
// async function. We assume that the caller who gets this
|
||||
// return is JavaScript.
|
||||
return Promise.resolve(ret);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
function proxy_convert_js_to_mp_obj_jsside(js_obj, out) {
|
||||
|
||||
Reference in New Issue
Block a user