Open meowtec opened 1 year ago
If you use a blocking function it will surely block.
Maybe you could instead run the blocking code to fetch the module asynchronously and then pass it on to load file.
If you use a blocking function it will surely block.
Maybe you could instead run the blocking code to fetch the module asynchronously and then pass it on to load file.
But JS_SetModuleLoaderFunc
only can receive a synchronously module_loader
. The type of module_loader
is:
typedef JSModuleDef *JSModuleLoaderFunc(JSContext *ctx,
const char *module_name, void *opaque);
(I am new to C language, I think that a asynchronously function should have a callback argument, is that right?)
Link this:
typedef void JSModuleLoaderFunc(JSContext *ctx,
const char *module_name, void *opaque, JSModuleLoaderCB cb);
@saghul
BTW, I tried import()
in txiki.js, and it also blocked:
setInterval(() => {
console.log(~~(Date.now() / 1000) % 100)
}, 1000)
// a simple http server that won't finish response
// this will block timer tasks
import('http://127.0.0.1:8989/').then(res => console.log(res.test))
Good catch, I should add a timeout for http imports!
So, is import()
still synchronous now? The only solution is to add timeout?
I think #351 is discussing something similar
Those were 2 separate issues. Imports are currently blocking.
I am trying to modify
js_load_file
function, with adding some long-time I/O operations inside it, such as requesting module file from remote server , or justsleep(10)
for test. After addsleep(10)
intojs_load_file
, the thread will be blocked byjs_dynamic_import_job
.It would be better to make
js_load_file
a non-blocking function, or inside another thread.