separate socket connection from event loop

This commit is contained in:
Masen Furer 2025-01-31 14:47:28 -08:00
parent 159d17cb53
commit 480bac98df
No known key found for this signature in database
GPG Key ID: 2AE2BD5531FF94F4

View File

@ -805,12 +805,8 @@ export const useEventLoop = (
}; };
}, []); }, []);
// Main event loop. // Handle socket connect/disconnect.
useEffect(() => { useEffect(() => {
// Skip if the router is not ready.
if (!router.isReady) {
return;
}
// only use websockets if state is present // only use websockets if state is present
if (Object.keys(initialState).length > 1) { if (Object.keys(initialState).length > 1) {
// Initialize the websocket connection. // Initialize the websocket connection.
@ -820,15 +816,9 @@ export const useEventLoop = (
dispatch, dispatch,
["websocket"], ["websocket"],
setConnectErrors, setConnectErrors,
client_storage client_storage,
); );
} }
(async () => {
// Process all outstanding events.
while (event_queue.length > 0 && !event_processing) {
await processEvent(socket.current);
}
})();
} }
// Cleanup function. // Cleanup function.
@ -839,6 +829,20 @@ export const useEventLoop = (
}; };
}, []); }, []);
// Main event loop.
useEffect(() => {
// Skip if the router is not ready.
if (!router.isReady) {
return;
}
(async () => {
// Process all outstanding events.
while (event_queue.length > 0 && !event_processing) {
await processEvent(socket.current);
}
})();
});
// localStorage event handling // localStorage event handling
useEffect(() => { useEffect(() => {
const storage_to_state_map = {}; const storage_to_state_map = {};