Content-Length: 294674 | pFad | http://github.com/micropython/micropython/commit/84d6f8e8cb993e82f03e209ffd49d5c44fc780e0

C9 webassembly/modjsffi: Add jsffi.async_timeout_ms. · micropython/micropython@84d6f8e · GitHub
Skip to content

Commit 84d6f8e

Browse files
committed
webassembly/modjsffi: Add jsffi.async_timeout_ms.
This function exposes `setTimeout()` as an async function. Signed-off-by: Damien George <damien@micropython.org>
1 parent 967ad38 commit 84d6f8e

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

Diff for: ports/webassembly/modjsffi.c

+15
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,27 @@ static mp_obj_t mp_jsffi_to_js(mp_obj_t arg) {
6161
}
6262
static MP_DEFINE_CONST_FUN_OBJ_1(mp_jsffi_to_js_obj, mp_jsffi_to_js);
6363

64+
// *FORMAT-OFF*
65+
EM_JS(void, promise_with_timeout_ms, (double ms, uint32_t * out), {
66+
const ret = new Promise((resolve) => setTimeout(resolve, ms));
67+
proxy_convert_js_to_mp_obj_jsside(ret, out);
68+
});
69+
// *FORMAT-ON*
70+
71+
static mp_obj_t mp_jsffi_async_timeout_ms(mp_obj_t arg) {
72+
uint32_t out[PVN];
73+
promise_with_timeout_ms(mp_obj_get_float_to_d(arg), out);
74+
return proxy_convert_js_to_mp_obj_cside(out);
75+
}
76+
static MP_DEFINE_CONST_FUN_OBJ_1(mp_jsffi_async_timeout_ms_obj, mp_jsffi_async_timeout_ms);
77+
6478
static const mp_rom_map_elem_t mp_module_jsffi_globals_table[] = {
6579
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_jsffi) },
6680

6781
{ MP_ROM_QSTR(MP_QSTR_JsProxy), MP_ROM_PTR(&mp_type_jsproxy) },
6882
{ MP_ROM_QSTR(MP_QSTR_create_proxy), MP_ROM_PTR(&mp_jsffi_create_proxy_obj) },
6983
{ MP_ROM_QSTR(MP_QSTR_to_js), MP_ROM_PTR(&mp_jsffi_to_js_obj) },
84+
{ MP_ROM_QSTR(MP_QSTR_async_timeout_ms), MP_ROM_PTR(&mp_jsffi_async_timeout_ms_obj) },
7085
};
7186
static MP_DEFINE_CONST_DICT(mp_module_jsffi_globals, mp_module_jsffi_globals_table);
7287

0 commit comments

Comments
 (0)








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/micropython/micropython/commit/84d6f8e8cb993e82f03e209ffd49d5c44fc780e0

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy