add pooling for game

This commit is contained in:
2026-08-01 16:46:41 +07:00
parent a71c1c9f6d
commit f8b4b6c6a8
5 changed files with 34 additions and 4 deletions
+25
View File
@@ -0,0 +1,25 @@
import { ref, onMounted, onUnmounted } from 'vue';
export function useSimplePolling(callback: () => void, interval = 5000) {
const isActive = ref(true);
let timerId: number | null = null;
const start = () => {
isActive.value = true;
callback();
timerId = window.setInterval(callback, interval);
};
const stop = () => {
isActive.value = false;
if (timerId) {
clearInterval(timerId);
timerId = null;
}
};
onMounted(start);
onUnmounted(stop);
return { isActive, start, stop };
}