patch js in a better way, fix event loop logic

This commit is contained in:
ading2210 2024-01-17 01:04:43 -05:00
parent 4af7f6a4a0
commit fc32c7c1fb
8 changed files with 57 additions and 21 deletions

View file

@ -8,6 +8,7 @@ window.libcurl = (function() {
/* __extra_libraries__ */
const websocket_url = `wss://${location.hostname}/ws/`;
var event_loop = null;
//a case insensitive dictionary for request headers
class Headers {
@ -88,15 +89,16 @@ function perform_request(url, params, js_data_callback, js_end_callback, body=nu
data_callback_ptr = Module.addFunction(data_callback, "vii");
_start_request(url_ptr, params_ptr, data_callback_ptr, end_callback_ptr, body_ptr, body_length);
_free(params_ptr);
if (!_active_requests()) {
//time out requests after a while
let event_loop = setInterval(() => {
_tick_request();
if (!event_loop) {
event_loop = setInterval(() => {
_tick_request();
if (!_active_requests()) {
clearInterval(event_loop);
event_loop = null;
}
}, 500);
}, 0);
}
}