Browse Source

Fixing too "long timer interval" warning by implemening a clock that triggers the

fetch function every 10min
master
GabrielTrettel 3 years ago
parent
commit
9a8051617a
  1. 28
      src/app/hooks/useSocketMarkers.js

28
src/app/hooks/useSocketMarkers.js

@ -158,8 +158,12 @@ function verifyResponse(response, name) {
function getFormsAnswers(socketObject, dispatch) {
const [socketResponse, setSocketResponse] = useState();
// GATO: Was getting an error due to too long timer (10min), so counting 10
// times 1 minute to fetch new sockets
const [timerCounter, setTimer] = useState(1);
const openListeners = () => {
console.log(`rodando forms answ ${socketObject.name}`);
// console.log(`rodando forms answ ${socketObject.name}`);
socketObject.socketUrl.onerror = (e) => {
console.log(e.message);
};
@ -169,24 +173,30 @@ function getFormsAnswers(socketObject, dispatch) {
};
};
openListeners()
openListeners();
// Actually closing/opening sockets every 10min
useEffect(() => {
const timer = setInterval(() => {
console.log(
"===== Runing interval " + socketObject.name + " ========"
);
if (timerCounter % 10 == 0) {
console.log("===== Runing interval " + socketObject.name + " ========" + timerCounter);
socketObject.socketUrl.close();
socketObject.socketUrl = new WebSocket(socketObject.url);
openListeners();
}, 600000);
}
}, [timerCounter]);
// Timer acting like a clock at F = 1/60 Hz
useEffect(() => {
const timer = setInterval(() => {
setTimer((oldTime) => oldTime + 1);
}, 60000);
return () => clearTimeout(timer);
}, []);
useEffect(() => {
dispatch({ increment: verifyResponse(socketResponse, socketObject.name)});
dispatch({ increment: verifyResponse(socketResponse, socketObject.name) });
}, [socketResponse]);
}

Loading…
Cancel
Save