prevent multiple requests at the same time

This commit is contained in:
Niki Wix Skaarup 2025-04-02 02:00:00 +02:00
parent a4d5e5d768
commit d41f907ab6
Signed by: nikiskaarup
GPG key ID: FC2F1B116F6E788C

View file

@ -8,7 +8,10 @@
clearInterval(interval); clearInterval(interval);
// Pooling interval to fetch entries every 31 seconds // Pooling interval to fetch entries every 31 seconds
let fetching = false;
interval = setInterval(async () => { interval = setInterval(async () => {
if (fetching) return;
fetching = true;
try { try {
const promise = fetchEntries(); const promise = fetchEntries();
// wait for the promise to resolve before assigning to prevent flash // wait for the promise to resolve before assigning to prevent flash
@ -16,6 +19,8 @@
entriesPromise = promise; entriesPromise = promise;
} catch (error) { } catch (error) {
console.error('Error fetching entries:', error); console.error('Error fetching entries:', error);
} finally {
fetching = false;
} }
}, 1000 * 31); }, 1000 * 31);