This commit is contained in:
2026-05-09 01:18:51 +02:00
parent 7116ee4619
commit 959970c150
132 changed files with 21310 additions and 0 deletions

View File

@@ -0,0 +1,35 @@
import { onUnmounted, ref } from 'vue';
export function usePolling(callback, intervalMs = 2000) {
const isPolling = ref(false);
let timer = null;
let consecutiveErrors = 0;
function start() {
if (timer) stop();
isPolling.value = true;
consecutiveErrors = 0;
timer = setInterval(async () => {
try {
const shouldStop = await callback();
consecutiveErrors = 0;
if (shouldStop) stop();
} catch {
consecutiveErrors++;
if (consecutiveErrors >= 3) stop();
}
}, intervalMs);
}
function stop() {
if (timer) {
clearInterval(timer);
timer = null;
}
isPolling.value = false;
}
onUnmounted(stop);
return { isPolling, start, stop };
}