Skip to content

Commit

Permalink
Rename function, call schedule outside of then()
Browse files Browse the repository at this point in the history
The idea is to call schedule() always, no matter if there is an error
or not. So call it outside of the then() block.
  • Loading branch information
agners committed Oct 7, 2024
1 parent dde1126 commit 02f0f5a
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions rootfs/usr/share/www/static/scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ function fetchLogs() {
}
});
}
}, scheduleFetchLogs());
});
scheduleFetchLogs();
}

function scheduleTry() {
Expand All @@ -112,7 +113,7 @@ function scheduleFetchLogs() {
scheduleTimeout = setTimeout(fetchLogs, 5000);
}

function fetchNetworkInfo() {
function fetchSupervisorInfo() {
fetch("/supervisor/network/info").then(function (res) {
if (!res.ok)
return;
Expand All @@ -137,19 +138,20 @@ function fetchNetworkInfo() {
}

});
}, scheduleFetchNetworkInfo());
});
scheduleFetchSupervisorInfo();
}

var scheduleNetworkTimeout;
var scheduleSupervisorTimeout;

function scheduleFetchNetworkInfo() {
clearTimeout(scheduleNetworkTimeout);
scheduleNetworkTimeout = setTimeout(fetchNetworkInfo, 5000);
function scheduleFetchSupervisorInfo() {
clearTimeout(scheduleSupervisorTimeout);
scheduleSupervisorTimeout = setTimeout(fetchSupervisorInfo, 5000);
}

scheduleTry();
fetchLogs();
fetchNetworkInfo();
fetchSupervisorInfo();

document.getElementById("show_logs").addEventListener("click", toggleLogs);
function toggleLogs(event) {
Expand Down Expand Up @@ -228,7 +230,7 @@ function setDns(ipv4nameservers, ipv6nameservers) {
if (!response.ok) {
throw new Error('Failed to update the interface');
}
fetchNetworkInfo();
fetchSupervisorInfo();
return response.json();
})
.then(data => {
Expand Down

0 comments on commit 02f0f5a

Please sign in to comment.