mirror of
https://github.com/ading2210/libcurl.js.git
synced 2025-05-12 14:00:01 -04:00
fix event loop logic again
This commit is contained in:
parent
fc32c7c1fb
commit
8bcfc2157c
3 changed files with 10 additions and 5 deletions
|
@ -9,6 +9,7 @@ window.libcurl = (function() {
|
|||
|
||||
const websocket_url = `wss://${location.hostname}/ws/`;
|
||||
var event_loop = null;
|
||||
var active_requests = 0
|
||||
|
||||
//a case insensitive dictionary for request headers
|
||||
class Headers {
|
||||
|
@ -76,6 +77,7 @@ function perform_request(url, params, js_data_callback, js_end_callback, body=nu
|
|||
_free(response_json_ptr);
|
||||
|
||||
if (error != 0) console.error("request failed with error code " + error);
|
||||
active_requests --;
|
||||
js_end_callback(error, response_info);
|
||||
}
|
||||
|
||||
|
@ -90,11 +92,14 @@ function perform_request(url, params, js_data_callback, js_end_callback, body=nu
|
|||
_start_request(url_ptr, params_ptr, data_callback_ptr, end_callback_ptr, body_ptr, body_length);
|
||||
_free(params_ptr);
|
||||
|
||||
active_requests ++;
|
||||
_tick_request();
|
||||
if (!event_loop) {
|
||||
event_loop = setInterval(() => {
|
||||
_tick_request();
|
||||
if (!_active_requests()) {
|
||||
if (_active_requests() || active_requests) {
|
||||
_tick_request();
|
||||
}
|
||||
else {
|
||||
clearInterval(event_loop);
|
||||
event_loop = null;
|
||||
}
|
||||
|
@ -190,7 +195,7 @@ function main() {
|
|||
Module.onRuntimeInitialized = main;
|
||||
return {
|
||||
fetch: libcurl_fetch,
|
||||
set_websocket: set_websocket_url,
|
||||
set_websocket: set_websocket_url
|
||||
}
|
||||
|
||||
})()
|
|
@ -1 +1 @@
|
|||
Subproject commit 0a80885090b6247f42bc07cc85b441d8d719f551
|
||||
Subproject commit 79ebf1517a17cfbeb427a3c6bea788c3e30704f6
|
|
@ -1 +1 @@
|
|||
Subproject commit 874734623e4dfc4652b34a1bc61e1e35ca86dee8
|
||||
Subproject commit a74dcabec6d8564a2e245421e710fff7928a99fb
|
Loading…
Add table
Add a link
Reference in a new issue